Saturday, December 1, 2012

Software Kamus Besar Bahasa Indonesia - KBBI Offline 1.4

Ini merupakan software yang sangat bermanfaat, digunakan untuk mencari kosakata yang terdapat dalam Kamus Besar Bahasa Indonesia dengan mudah. Pada saat posting ini dibuat software KBBI telah sampai pada versi 1.4. Kamus Besar Bahasa Indonesia versi software ini dibuat oleh Ebta Setiawan pemilik situs: http://ebsoft.web.id. Software Kamus Besar Bahasa Indonesia ini bersifat opensource, dibuat dengan menggunakan bahasa pemrograman delphi.
Adapun fitur-fitur yang terdapat pada KBBI 1.4, diantaranya:
  • Pencarian kata/kalimat dari arti/definisi
  • Opsi pengaturan penggunaan auto search (bawaan tidak aktif)
  • Opsi pengaturan jumlah halaman kata hasil pencarian
  • Penjelasan tentang arti singkatan (jenis kata, istilah dll)
  • Icon baru
  • Tersedia versi installer dan portable
  • Lisensi menjadi Freeware & Open Source
  • Perbaikan pencarian kata yg ada tanda - didepannya
  • Perbaikan penebalan nomor/urutan arti kata
  • Perbaikan beberapa kata yang belum masuk (bising, durian, uang, sarasehan dan romantisisme)
  • Perbaikan hasil pencarian lainnya
  • Fitur pencarian otomatis tidak aktif secara bawaan (penambahan tombol cari)
  • Perbaikan tampilan font yang mengecil di Windows 8
Untuk download dan lain sebagainya bisa kunjungi link di samping: KBBI Offline 1.4 
 
Keywords: kbbi, offline, 1.4, software, kamus, besar, bahasa, indonesia, v1.5, online, istilah, arab, windows, 7, inggris, download, on, line, pemrograman, (kbbi), versi, kosakata
READ MORE - Software Kamus Besar Bahasa Indonesia - KBBI Offline 1.4

Friday, November 30, 2012

VB6 Database: Koneksi Access 2007 ke VB6

Koneksi VB6 dengan Access 2007: di bawah ini merupakan contoh kode sederhana untuk mengkoneksiakan Access 2007 dengan VB6, Adapun contoh kode untuk mengkoneksikan VB6 dengan Access 2007 adalah sebagai berikut:

Option Explicit

'-----------------------------------------------------------------------------------
' http://khoiriyyah.blogspot.com
'-----------------------------------------------------------------------------------

Dim conn As New ADODB.Connection

Private Sub Command1_Click()
Static i As Integer
i = i + 1
conn.Execute "INSERT INTO tbTest (fdTest)VALUES('Record ke-" & i & "')"
End Sub

Private Sub Form_Load()
If Not OpenAccess2007 Then
MsgBox Err.Description
End If
End Sub

Private Function OpenAccess2007() As Boolean
On Error GoTo ErrHandler
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & App.Path & "\test.accdb;Persist Security Info=False;"
OpenAccess2007 = True
Exit Function
ErrHandler:
End Function

Download: Source Code VB6 - Koneksi Access 2007 ke VB6.

Demikian contoh kode sederhana untuk mengkoneksikan Access 2007 dengan VB6.

Tags: koneksi vb6 dengan access 2007, koneksi access 2007 ke vb6, koneksi vb6 ke access 2007.

READ MORE - VB6 Database: Koneksi Access 2007 ke VB6

Sunday, August 5, 2012

Muslims For Marriage Sites

  1. Muslim Marriage - Qiran.com
    Site:
    www.qiran.com
          
  2. Muslims For Marriage - Find Your Indonesian Partner Now
    Site:
    www.indonesiancupid.com/
           
  3. Muslim MuslimMatch.com - 125,000+ Members
    Site:
    www.muslimmatch.com/
           
  4. USA Matrimonials Muslim
    Site:
    www.simplymarry.com/Matrimonials
         
  5. Muslim Singles Dating
    Site:
    www.muslimati.com/
          
  6. Muslim Marriage Online
    Site:
    www.look4marriage.com/
           
  7. Muslim Wedding
    Site:
    www.valentine.com/
           
  8. Indian Muslim Girls
    Site:
    www.marryasunni.com/
           
  9. Muslim_Girls Life as a Muslim Wife
    Site:
    www.eclecticwomen.org/
            
  10. Muslima
    Site:
    www.muslima.com
READ MORE - Muslims For Marriage Sites

Wednesday, July 4, 2012

VB6 Facebook: Mengakses Facebook Graph API

Mengenai teka-teki mengakses Facebook graph API - Agar tidak membosankan kali ini saya ajak Anda untuk bermain teka-teki saja, apakah semuanya setuju? oh, ternyata semuanya setuju. Baiklah teka-teki kali ini mengenai cara mengendalikan Facebook yang kita miliki dari aplikasi VB6 yang kita buat menggunakan Graph API. Di sini hanya diwakili dengan aplikasi facebook uploader sederhana. Untuk membuat aplikasi tersebut tidak sederhana/rumit, baik, user friendy maka kita membutuhkan satu lagi pemahaman mengenai JSON parser.

Tidak seperti Twitter yang menggunakan OAuth 1.0 yang sangat memusingkan kepala pada saat pembuatan digital signature yang valid (seperti yang telah saya posting sebelumnya, maka pada Facebook prosesnya jauh lebih sederhana kita hanya memerlukan access_token jangka panjang itu saja, atau access_token yang digenerate on the fly melalui OAuth 2.0, jadi kita sudah tidak memerlukan lagi password dan email untuk proses otentifikasi dan otorisasi yang tentu saja sangat tidak aman (berpotensi terjadinya pembajakan akun secara besar-besaran) dan ini sudah tidak dianjurkan lagi baik oleh Google, Facebook, Twitter, .dll (termasuk .ocx juga?).

Mengenai cara memperoleh access_token dari Facebook, silakan Anda cari di Google.

VB6 Facebook Graph API - Photo Uploader
Gambar: Upload photo ke Facebook melalui VB6
Demikian teka-teki kali ini mengenai cara mengakses Facebook graph API melalui aplikasi VB6. Baca juga teka-teka sebelumnya:
READ MORE - VB6 Facebook: Mengakses Facebook Graph API

Friday, June 29, 2012

VB6 Source Code: Membuat Frame Dari OptionButton - CheckBox

Mengenai cara membuat Frame dari objek OptionButton atau ChekBox - Dikarenakan objek CheckBox, OptionButton, kemudian CommandButton
berasal dari kelas yang sama yaitu Class Button, maka ketiganya pun dapat kita rubah stylenya menjadi sebuah Frame dengan memanfaatkan konstanta BS_GROUPBOX dan BM_SETSTYLE melalui bantuan fungsi API SendMessage. Keuntungan membuat Frame dari OptionButton, CheckBox atau CommandButton adalah dapat mengikuti Style Windows.
Adapun kode untuk merubah style CheckBox atau OptionButton menjadi Frame sebagai berikut:
'Simpan pada form
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
        ByVal hWnd As Long, _
        ByVal wMsg As Long, _
        ByVal wParam As Long, _
        lParam As Any) As Long
         
Private Const BM_SETSTYLE As Long = &HF4
Private Const BS_GROUPBOX As Long = &H7&
 
'Contoh penggunaan
Private Sub Form_Load()
    SendMessage Check1.hWnd, BM_SETSTYLE, BS_GROUPBOX, 0
End Sub

Catatan: Jangan lupa untuk merubah property ClipsControl yang terdapat pada Form menjadi False.
Download: Source Code
READ MORE - VB6 Source Code: Membuat Frame Dari OptionButton - CheckBox

Tuesday, June 26, 2012

VB6 Animasi: Menggunakan Fungsi API AnimateWindow

VB6 AnimateWindow - Dengan menggunakan fungsi API AnimateWindow, kita dapat membuat efek-efek animasi yang sangat halus. Fungsi API AnimateWindow sendiri tidak bisa digunakan begitu saja, tetapi ia membutuhkan bantuan fungsi API yang lain untuk melakukan SubClassing guna memproses Message WM_PRINT atau WM_PRINTCLIENT agar form yang sedang melakukan animasi terefresh dengan baik, dengan demikian form akan ditampilkan secara sempurna dan terhindar dari warna hitam yang menutupi keseluruhan form tersebut.

Modul AnimateWindow di bawah ini diperoleh dari situs Eduardo A. Morcillo. Nah, pada akhirnya untuk mempermudah penggunaan saya tambahkan beberapa baris Enum Animation, seperti di bawah ini:

Public Enum Animation
'// ACTIVATE
ACTIVATE_SLIDE_FROM_TOP = (AW_ACTIVATE Or AW_SLIDE Or AW_VER_POSITIVE)
ACTIVATE_SLIDE_FROM_BOTTOM = (AW_ACTIVATE Or AW_SLIDE Or AW_VER_NEGATIVE)
ACTIVATE_SLIDE_FROM_LEFT = (AW_ACTIVATE Or AW_SLIDE Or AW_HOR_POSITIVE)
ACTIVATE_SLIDE_FROM_RIGHT = (AW_ACTIVATE Or AW_SLIDE Or AW_HOR_NEGATIVE)
ACTIVATE_SLIDE_EXPAND_FROM_TOP_LEFT = (AW_ACTIVATE Or AW_SLIDE Or AW_HOR_POSITIVE Or AW_VER_POSITIVE)
ACTIVATE_SLIDE_EXPAND_FROM_BOTTOM_RIGHT = (AW_ACTIVATE Or AW_SLIDE Or AW_HOR_NEGATIVE Or AW_VER_NEGATIVE)
ACTIVATE_SLIDE_EXPAND_FROM_TOP_RIGHT = (AW_ACTIVATE Or AW_SLIDE Or AW_HOR_NEGATIVE Or AW_VER_POSITIVE)
ACTIVATE_SLIDE_EXPAND_FROM_BOTTOM_LEFT = (AW_ACTIVATE Or AW_SLIDE Or AW_HOR_POSITIVE Or AW_VER_NEGATIVE)
ACTIVATE_SLIDE_EXPAND_FROM_CENTER = (AW_ACTIVATE Or AW_SLIDE Or AW_CENTER)
ACTIVATE_SLIDE_FADE_TRANSITION = (AW_ACTIVATE Or AW_BLEND)
'// DEACTIVATE
DEACTIVATE_SLIDE_FADE_TRANSITION = (AW_HIDE Or AW_BLEND)
DEACTIVATE_SLIDE_TO_TOP = (AW_HIDE Or AW_SLIDE Or AW_VER_NEGATIVE)
DEACTIVATE_SLIDE_TO_BOTTOM = (AW_HIDE Or AW_SLIDE Or AW_VER_POSITIVE)
DEACTIVATE_SLIDE_TO_LEFT = (AW_HIDE Or AW_SLIDE Or AW_HOR_NEGATIVE)
DEACTIVATE_SLIDE_TO_RIGHT = (AW_HIDE Or AW_SLIDE Or AW_HOR_POSITIVE)
DEACTIVATE_SLIDE_SHRINK_TO_TOP_LEFT = (AW_HIDE Or AW_SLIDE Or AW_HOR_NEGATIVE Or AW_VER_NEGATIVE)
DEACTIVATE_SLIDE_SHRINK_TO_BOTTOM_RIGHT = (AW_HIDE Or AW_SLIDE Or AW_HOR_POSITIVE Or AW_VER_POSITIVE)
DEACTIVATE_SLIDE_SHRINK_TO_TOP_RIGHT = (AW_HIDE Or AW_SLIDE Or AW_HOR_POSITIVE Or AW_VER_NEGATIVE)
DEACTIVATE_SLIDE_SHRINK_TO_BOTTOM_LEFT = (AW_HIDE Or AW_SLIDE Or AW_HOR_NEGATIVE Or AW_VER_POSITIVE)
DEACTIVATE_SLIDE_SHRINK_TO_CENTER = (AW_HIDE Or AW_SLIDE Or AW_CENTER)
End Enum
Adapun modul lengkapnya adalah sebagai berikut:
Option Explicit

Const GWL_WNDPROC = (-4)

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Const PROP_PREVPROC = "PrevProc"
Const PROP_FORM = "FormObject"

Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hWnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hWnd As Long, ByVal lpString As String) As Long

Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal DestL As Long)

Const WM_PRINTCLIENT = &H318

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function apiOleTranslateColor Lib "oleaut32" Alias "OleTranslateColor" (ByVal lOleColor As Long, ByVal lHPalette As Long, lColorRef As Long) As Long

Enum AnimateWindowFlags
AW_HOR_POSITIVE = &H1
AW_HOR_NEGATIVE = &H2
AW_VER_POSITIVE = &H4
AW_VER_NEGATIVE = &H8
AW_CENTER = &H10
AW_HIDE = &H10000
AW_ACTIVATE = &H20000
AW_SLIDE = &H40000
AW_BLEND = &H80000
End Enum

Private Declare Function apiAnimateWindow Lib "user32" Alias "AnimateWindow" (ByVal hWnd As Long, ByVal dwTime As Long, ByVal dwFlags As Long) As Long
Private Declare Function MulDiv Lib "kernel32" (ByVal Mul As Long, ByVal Nom As Long, ByVal Den As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hDC As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Enum Animation
'// ACTIVATE
ACTIVATE_SLIDE_FROM_TOP = (AW_ACTIVATE Or AW_SLIDE Or AW_VER_POSITIVE)
ACTIVATE_SLIDE_FROM_BOTTOM = (AW_ACTIVATE Or AW_SLIDE Or AW_VER_NEGATIVE)
ACTIVATE_SLIDE_FROM_LEFT = (AW_ACTIVATE Or AW_SLIDE Or AW_HOR_POSITIVE)
ACTIVATE_SLIDE_FROM_RIGHT = (AW_ACTIVATE Or AW_SLIDE Or AW_HOR_NEGATIVE)
ACTIVATE_SLIDE_EXPAND_FROM_TOP_LEFT = (AW_ACTIVATE Or AW_SLIDE Or AW_HOR_POSITIVE Or AW_VER_POSITIVE)
ACTIVATE_SLIDE_EXPAND_FROM_BOTTOM_RIGHT = (AW_ACTIVATE Or AW_SLIDE Or AW_HOR_NEGATIVE Or AW_VER_NEGATIVE)
ACTIVATE_SLIDE_EXPAND_FROM_TOP_RIGHT = (AW_ACTIVATE Or AW_SLIDE Or AW_HOR_NEGATIVE Or AW_VER_POSITIVE)
ACTIVATE_SLIDE_EXPAND_FROM_BOTTOM_LEFT = (AW_ACTIVATE Or AW_SLIDE Or AW_HOR_POSITIVE Or AW_VER_NEGATIVE)
ACTIVATE_SLIDE_EXPAND_FROM_CENTER = (AW_ACTIVATE Or AW_SLIDE Or AW_CENTER)
ACTIVATE_SLIDE_FADE_TRANSITION = (AW_ACTIVATE Or AW_BLEND)
'// DEACTIVATE
DEACTIVATE_SLIDE_FADE_TRANSITION = (AW_HIDE Or AW_BLEND)
DEACTIVATE_SLIDE_TO_TOP = (AW_HIDE Or AW_SLIDE Or AW_VER_NEGATIVE)
DEACTIVATE_SLIDE_TO_BOTTOM = (AW_HIDE Or AW_SLIDE Or AW_VER_POSITIVE)
DEACTIVATE_SLIDE_TO_LEFT = (AW_HIDE Or AW_SLIDE Or AW_HOR_NEGATIVE)
DEACTIVATE_SLIDE_TO_RIGHT = (AW_HIDE Or AW_SLIDE Or AW_HOR_POSITIVE)
DEACTIVATE_SLIDE_SHRINK_TO_TOP_LEFT = (AW_HIDE Or AW_SLIDE Or AW_HOR_NEGATIVE Or AW_VER_NEGATIVE)
DEACTIVATE_SLIDE_SHRINK_TO_BOTTOM_RIGHT = (AW_HIDE Or AW_SLIDE Or AW_HOR_POSITIVE Or AW_VER_POSITIVE)
DEACTIVATE_SLIDE_SHRINK_TO_TOP_RIGHT = (AW_HIDE Or AW_SLIDE Or AW_HOR_POSITIVE Or AW_VER_NEGATIVE)
DEACTIVATE_SLIDE_SHRINK_TO_BOTTOM_LEFT = (AW_HIDE Or AW_SLIDE Or AW_HOR_NEGATIVE Or AW_VER_POSITIVE)
DEACTIVATE_SLIDE_SHRINK_TO_CENTER = (AW_HIDE Or AW_SLIDE Or AW_CENTER)
End Enum

Function AnimateWindow(ByVal Form As Object, ByVal dwTime As Long, ByVal dwFlags As Animation)
Dim ctl As Control

SetProp Form.hWnd, PROP_PREVPROC, GetWindowLong(Form.hWnd, GWL_WNDPROC)
SetProp Form.hWnd, PROP_FORM, ObjPtr(Form)
Dim i As Integer
SetWindowLong Form.hWnd, GWL_WNDPROC, AddressOf AnimateWinProc
apiAnimateWindow Form.hWnd, dwTime, dwFlags
SetWindowLong Form.hWnd, GWL_WNDPROC, GetProp(Form.hWnd, PROP_PREVPROC)
RemoveProp Form.hWnd, PROP_FORM
RemoveProp Form.hWnd, PROP_PREVPROC
Form.Refresh
For Each ctl In Form.Controls
ctl.Visible = Not ctl.Visible
ctl.Visible = Not ctl.Visible
Next
End Function

Private Function AnimateWinProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Dim lPrevProc As Long
Dim lForm As Long
Dim oForm As Form

lPrevProc = GetProp(hWnd, PROP_PREVPROC)

lForm = GetProp(hWnd, PROP_FORM)
MoveMemory oForm, lForm, 4&

Select Case Msg
Case WM_PRINTCLIENT
Dim tRect As RECT
Dim hBr As Long
GetClientRect hWnd, tRect
hBr = CreateSolidBrush(OleTranslateColor(oForm.BackColor))
FillRect wParam, tRect, hBr
DeleteObject hBr

If Not oForm.Picture Is Nothing Then
Dim lScrDC As Long
Dim lMemDC As Long
Dim lPrevBMP As Long
lScrDC = GetDC(0&)
lMemDC = CreateCompatibleDC(lScrDC)
ReleaseDC 0, lScrDC
lPrevBMP = SelectObject(lMemDC, oForm.Picture.Handle)
BitBlt wParam, 0, 0, HM2Pix(oForm.Picture.Width), HM2Pix(oForm.Picture.Height), lMemDC, 0, 0, vbSrcCopy
SelectObject lMemDC, lPrevBMP
DeleteDC lMemDC
End If
End Select

MoveMemory oForm, 0&, 4&
AnimateWinProc = CallWindowProc(lPrevProc, hWnd, Msg, wParam, lParam)

End Function

Private Function HM2Pix(ByVal Value As Long) As Long
HM2Pix = MulDiv(Value, 1440, 2540) / Screen.TwipsPerPixelX
End Function

Private Function OleTranslateColor(ByVal Clr As Long) As Long
apiOleTranslateColor Clr, 0, OleTranslateColor
End Function

Public Function AnimationX(frm As Object, lTime As Long, eMode As Animation)
AnimateWindow frm, lTime, eMode
End Function
Simpanlah kode diatas pada sebuah module. Adapun contoh penggunaannya adalah sebagai berikut:
Private Sub Form_Load()
AnimateWindow Me, 300, ACTIVATE_SLIDE_EXPAND_FROM_CENTER
End Sub

Private Sub Form_Unload(Cancel As Integer)
AnimateWindow Me, 300, DEACTIVATE_SLIDE_SHRINK_TO_CENTER
End Sub
Harap diingat, flags yang diawali dengan ACTIVATE untuk memulai dan flags yang diakhiri dengan DEACTIVATE untuk mengakhiri. Akhirnya saya jadi teringat beberapa software yang menggunakan efek animasi seperti ini, diantaranya adalah Mufid (software kamus) yang menggunakan efek slide kemudian SpeedComander (software utility) yang menggunakan efek center.
READ MORE - VB6 Animasi: Menggunakan Fungsi API AnimateWindow

Error: File not found: "C:\Windows\system32\ieframe.dll\1"

Mengenai cara mengatasi File not found: "C:\Windows\system32\ieframe.dll\1" secara otomatis dan mudah, anggap saja sebuah trik.

Bekerja dengan objek WebBrowser atau Microsoft Internet Control, terkadang kita sering berhadapan dengan error: File not found: "C:\Windows\system32\ieframe.dll\1" akibat perubahan nilai yang terdapat pada registry. Walaupun error tersebut bukanlah suatu hal yang serius dan sangat mudah diatasi, tetapi bagaimana jika kejadiannya berulang-ulang? sungguh sesuatu hal yang sangat mengesalkan.

Berdasarkan hal yang telah saya sebutkan di atas, akhirnya saya membuat sebuah tools untuk mengatasi hal ini, tools tersebut dapat bekerja dengan otomatis. Tools tersebut dibuat berdasarkan fakta, bahwa Add-Ins lebih dahulu dijalankan oleh VB6 sebelum melakukan Load terhadap seluruh objek. Jadi kata kuncinya adalah merubah registry menggunakan Add-Ins, adapun kodenya saya bagi dua: yang pertama terdapat pada Connect.dsr dan yang kedua terdapat pada module yang saya namakan dengan modRegistry.bas. Adapun penampakan kodenya adalah sebagai berikut:

Connect.dsr

Option Explicit

Public FormDisplayed As Boolean
Public VBInstance As VBIDE.VBE
Dim mcbMenuCommandBar As Office.CommandBarControl
Public WithEvents MenuHandler As CommandBarEvents

Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
On Error GoTo error_handler
Set VBInstance = Application

Debug.Print VBInstance.FullName
RegWrite "HKEY_CLASSES_ROOT\TypeLib\{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}\1.1\0\win32\", "C:\WINDOWS\system32\ieframe.dll"
If ConnectMode = ext_cm_External Then
RegWrite "HKEY_CLASSES_ROOT\TypeLib\{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}\1.1\0\win32\", "C:\WINDOWS\system32\ieframe.dll"
Else
Set mcbMenuCommandBar = AddToAddInCommandBar("Handle Internet Error")
Set Me.MenuHandler = VBInstance.Events.CommandBarEvents(mcbMenuCommandBar)
End If

If ConnectMode = ext_cm_AfterStartup Then
If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
RegWrite "HKEY_CLASSES_ROOT\TypeLib\{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}\1.1\0\win32\", "C:\WINDOWS\system32\ieframe.dll"
End If
End If

Exit Sub

error_handler:

MsgBox Err.Description

End Sub

Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
On Error Resume Next
mcbMenuCommandBar.Delete
If FormDisplayed Then
SaveSetting App.Title, "Settings", "DisplayOnConnect", "1"
FormDisplayed = False
Else
SaveSetting App.Title, "Settings", "DisplayOnConnect", "0"
End If
End Sub

Private Sub IDTExtensibility_OnStartupComplete(custom() As Variant)
If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
End If
End Sub

Function AddToAddInCommandBar(sCaption As String) As Office.CommandBarControl
Dim cbMenuCommandBar As Office.CommandBarControl
Dim cbMenu As Object

On Error GoTo AddToAddInCommandBarErr

Set cbMenu = VBInstance.CommandBars("Add-Ins")
If cbMenu Is Nothing Then
Exit Function
End If

Set cbMenuCommandBar = cbMenu.Controls.Add(1)
cbMenuCommandBar.Caption = sCaption

Set AddToAddInCommandBar = cbMenuCommandBar

Exit Function

AddToAddInCommandBarErr:

End Function
modRegistry.bas:
Option Explicit

Dim oWSHShell As WshShell

"untuk menulisi registry
Public Function RegWrite(sKey As String, sFilepath As String) As Boolean
On Error GoTo Err
Set oWSHShell = New WshShell
oWSHShell.RegWrite sKey, sFilepath
Set oWSHShell = Nothing
RegWrite = True
Exit Function
Err:
RegWrite = False
End Function

"untuk menghapus key dari registry
Public Function RegDelete(sKey As String) As Boolean
On Error GoTo Err
Set oWSHShell = New WshShell
oWSHShell.RegDelete sKey
Set oWSHShell = Nothing
RegDelete = True
Exit Function
Err:
RegDelete = False
End Function

"untuk membaca key dari registry
Public Function RegRead(strKey)
On Error Resume Next
Set oWSHShell = New WshShell
RegRead = oWSHShell.RegRead(strKey)
Set oWSHShell = Nothing
End Function

Langkah-langkah pembuatan:

  1. Buat project Add-Ins.
  2. Ganti seluruh kode yang terdapat pada Connect.dsr dengan kode di atas.
  3. Tambahkan satu Module dan beri nama dengan module modRegistry
  4. Simpan Project dan lakukan Compile
  5. Lakukan register dll apabila project yang Anda buat belum terigistrasi pada registry

Sekarang Anda tidak akan pernah diganggu lagi dengan error: File not found: "C:\Windows\system32\ieframe.dll\1" selamanya. Terakhir, mari kita ucapkan bersama, selamat tinggal error: File not found: "C:\Windows\system32\ieframe.dll\1"

READ MORE - Error: File not found: "C:\Windows\system32\ieframe.dll\1"

Monday, June 25, 2012

VB6 Animasi: Animasi Melayang Ala Google Talk

Mengenai animasi melayang pada saat tampil dan sembunyi di systray ala Google Talk menggunakan VB6.
Const IDANI_OPEN = &H1
Const IDANI_CLOSE = &H2
Const IDANI_CAPTION = &H3

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function SetRect Lib "User32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DrawAnimatedRects Lib "User32" (ByVal hwnd As Long, ByVal idAni As Long, lprcFrom As RECT, lprcTo As RECT) As Long
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Public Sub ShowMinimzeToSysTray(ByVal hwnd As Long)
Dim rSource As RECT, rDest As RECT
GetWindowRect hwnd, rSource
GetWindowRect FindWindowEx(FindWindow("Shell_TrayWnd", vbNullString), 0, "TrayNotifyWnd", vbNullString), rDest
Call DrawAnimatedRects(hwnd, IDANI_CLOSE Or IDANI_CAPTION, rSource, rDest)
End Sub

Public Sub ShowRestoreFromSysTray(ByVal hwnd As Long)
Dim rSource As RECT, rDest As RECT
GetWindowRect FindWindowEx(FindWindow("Shell_TrayWnd", vbNullString), 0, "TrayNotifyWnd", vbNullString), rSource
GetWindowRect hwnd, rDest
Call DrawAnimatedRects(hwnd, IDANI_OPEN Or IDANI_CAPTION, rSource, rDest)
End Sub

Private Sub Command2_Click()
ShowMinimzeToSysTray hwnd
End Sub

Private Sub Command1_Click()
ShowRestoreFromSysTray Me.hwnd
End Sub
Kode di atas, akan menjadi tidak bermanfaat apabila aplikasi tidak menggunakan/memanfaatkan systray icon untuk menampilkan dan menyembunyikan aplikasi.
READ MORE - VB6 Animasi: Animasi Melayang Ala Google Talk

theBatch Add-Ins, Mengatasi Beberapa Masalah Manifest Resour

Ini merupakan aplikasi VB6 Add-Ins, saya namakan dengan theBatch, karena ia dapat menyelesaikan masalah form yang disebabkan manifest resource secara bersamaan/sekaligus berapapun banyaknya form tersebut. Modul utamanya milik Eduardo A. Morcillo and Vlad Vissoultchev (pembuat Hook Menu).

Beberapa masalah manifest tersebut, diantaranya:
  1. Flickering pada frame
  2. Hilangnya mnemonic (shorcut underline), ini sangat mengganggu dalam aplikasi database.
  3. CommandButton yang ditempatkan pada frame akan memiliki border hitam disekelilingnya
  4. CommandButton dengan property Style = 1 - Graphical, tidak bisa ditheme XP
  5. OptionButton yang dtempatkan pada frame akan memiliki background hitam
Download: theBatch dan Sample UI.
READ MORE - theBatch Add-Ins, Mengatasi Beberapa Masalah Manifest Resour

Download Software Speech/Voice Recognition

Ini merupakan software pembelajaran untuk melatih mengucapkan frase-frase pendek dalam percakapan. Adapun yang menjadi lawan bicaranya adalah sebuah komputer.

Cara menggunakan:
  1. Isi terlebih dahulu database percakapan yang terdapat pada C:\Program Files\Speech\dbase.mdb. Isi dari percakapan tersebut disesuaikan dengan kebutuhan Anda atau anak didik Anda.
  2. Siapkan mikrofon berkualitas baik
  3. Atur volume
  4. Bacalah frase-frase pendek yang telah Anda isi ke dalam database yang terdapat pada sisi kiri. Selanjutnya komputer akan menjawabnya.
Keunggulan dari software ini adalah sangat sederhana, sehingga sangat mudah untuk digunakan. Disamping itu ukurannya sangat kecil, sekitar 400kb lebih. Nah, selamat berlatih dan bercakap-cakap dengan komputer dan Insya Allah dikembangkan jika ada waktu.

Download: Speech 1.5
READ MORE - Download Software Speech/Voice Recognition

Software - Simple SQL Query Tester 2.0 Open Source

Ini merupakan software sederhana untuk menguji connection string beberapa database serta menguji sql query meliputi INSERT, UPDATE, SELECT, DELETE selanjutnya melalui software ini, Anda dapat merubahnya menjadi Visual Basic String dan mengcopy paste pada project yang sedang Anda buat.Selain yang telah dijelaskan, Anda pun dapat mempelajari pembuatan script installer untuk pembuatan file setup, dan beberapa code VB6 yang kebanyakan telah dituliskan pada postingan secara terpisah.

Catatan:

  1. Compile terlebih dahulu menjadi file .exe, karena ada sedikit perbedaan antara design time dan runtime.
  2. Apabila Anda berkeinginan membuat file setup, download terlebih dahulu innosetup installer kemudian klik kanan pada file Application.iss >> compile. maka pada folder output Anda akan mendapati file Query Tester.EXE yang merupakan file setup.
Download: Query Tester (Source Code)
Download: Query Tester (Setup)
READ MORE - Software - Simple SQL Query Tester 2.0 Open Source

Update: My Source Online 2.0 - Online MySQL Database

Rupanya pada versi yang sebelumnya terjadi beberapa kegagalan, diantaranya:
  1. Gagal dalam mengecek koneksi internet, modul yang digunakan adalah -[memeriksa keberadaan koneksi internet]- sehingga selalu terkadang menampilkan pesan error "Mohon maaf, tidak ada koneksi internet".
  2. Gagal dalam meregistrasikan COMDLG32.OCX (CommonDialog ActiveX), kemungkinan masalah versi.
Kedua masalah tersebut telah saya perbaiki, pertama dengan mengganti modul check koneksi internet masalah kedua diatasi dengan cara mengganti COMDLG32.OCX dengan class yang diembed langsung pada aplikasi.

Catatan: karena aplikasi ini tidak dilengkapi dengan file-file runtime (hanya dua ActiveX yang disertakan vbSendMail dan CMAX20.OCX [Syntax Hightlighter]), maka sebaiknya Anda lengkapi dulu runtimenya dan beberapa file untuk mengakses database MySQL, atau Anda rujuk pada link di bawah ini:
  1. Aplikasi Minimarket (menggunakan database MySQL, lengkap beserta file-file runtime yang dibutuhkan)
  2. MySQL ODBC 3.51 Driver
Nah, setelah menjalankan dua file di atas, seharusnya Anda sudah dapat mengakses database MySQL secara online menggunakan VB6.
READ MORE - Update: My Source Online 2.0 - Online MySQL Database

Aplikasi iImsyakiyah Dari http://www.diajar.com

Aplikasi iImsyakiyah ini dibuat oleh saudara Agung Novian pemiliki situs http://www.diajar.com. Aplikasi ini digunakan untuk memberitahukan jadwal sholat lima waktu.

Keterangan mengenai Aplikasi iImsyakiyah:
  • Dibuat menggunakan bahasa pemrograman Visual Basic 6.
  • Portable, artinya tidak memerlukan penginstallan.
  • GUI yang menarik dan serasi.
  • Dilengkapi dengan tray icon.
  • Alarm untuk memberitahukan waktu imsyak, dan adzan untuk memberitahukan waktu shalat (bisa dirubah settingannya).
  • Dilengkapi fasilitas shutdown dan hibernate
  • Walaupun aplikasi hanya mencantumkan tiga daerah (Jakarta, Bandung, dan Cirebon) tetapi Anda dapat dengan mudah menambahkan nama daerah, dengan terlebih dahulu menyesuaikan settingannya, seperti tampak pada gambar di bawah ini:
Bagi Anda yang berminat memiliki aplikasinya, Anda dapat mengunjungi tautan di samping http://www.diajar.com/#/aplikasi-iimsakiyahv1-1. Kritik dan saran mengenai aplikasi ini bisa Anda kirimkan ke alamat email disamping:
pujanggabageur[at]yahoo.com (ganti [at] dengan @)

Terima kasih semoga bermanfaat.
READ MORE - Aplikasi iImsyakiyah Dari http://www.diajar.com

Wednesday, June 20, 2012

Cara Yang Cerdik Untuk Mentrap On Error Resume Next - VB6

Mengenai cara men-trap (menjebak) objek error yang berada di bawah bari On Error Resume Next - Bagaimana kita dapat melakukan sebuah pengecualian dalam baris yang berada di bawah On Error Resume Next, di bawah adalah contoh kode VB6 beserta penjelasannya:
Option Explicit

Private Sub Command1_Click()
'Baris pertama kita memasang On Error Resume Next, maksudnya
'kita memberitahukan pada compiler VB6 untuk melangkahi baris error
'dan mengeksekusi baris berikutnya tanpa harus menampilkan pesan error
On Error Resume Next

'Selanjutnya kita mamasang satu variable i (catatan: variable satu huruf
'seperti i, b, j dan selanjutnya, hanya bisa digunakan pada sebuah jangkah (scope)
'yang sempit, dan jangan pernah menggunakannya pada scope yang luas seperti
'Public i as Integer dan variable i berada pada module, Global l as long, dst
Dim i As Integer

'Dengan adanya On Error Resume Next di atas, maka kode di bawah ini akan
'diabaikan/dilangkahi oleh compiler VB6. Selanjutnya pesan error tidak akan
'ditampilkan
i = "Hai, ini pasti error"

'Walaupun kita telah memasang baris On Error Resume Next, bukan berarti
'Bukan berarti Error Object tidak, Error Object tetap bekerja sebagaimana
'biasanya
If Err Then 'Apabila Error = True a.k.a Err.Number > 0 maka ...
'Kode trap ...
MsgBox Err.Description
'Kode trap ...
End If

'Baris di bawah akan meng-Clear error
On Error GoTo 0

'Sekarang lihat hasilnya
MsgBox Err.Description
End Sub
Kode utuh tanpa keterangan (comment) adalah sebagai berikut:
Option Explicit

Private Sub Command1_Click()
On Error Resume Next
Dim i As Integer
i = "Hai, ini pasti error"
If Err Then
MsgBox Err.Description
End If
On Error GoTo 0
MsgBox Err.Description
End Sub
READ MORE - Cara Yang Cerdik Untuk Mentrap On Error Resume Next - VB6

Sunday, June 17, 2012

Contoh Menambahkan Attribut Pada Tag HTML - VB Code

Private Function AddPreWithClassName()
Dim d As New MSHTML.HTMLDocument
Dim l As HTMLMetaElement
Dim x As HTMLHtmlElement

d.body.innerHTML = txtPost.Text

For Each l In d.All
If l.tagName = "PRE" Then
l.className = "code" '
End If
Next
txtPost.Text = d.body.innerHTML
End Function
READ MORE - Contoh Menambahkan Attribut Pada Tag HTML - VB Code

URL Encode - Decode UTF8 Menggunakan Script Control

Mungkin bisa disebut sebagai cara termudah untuk melakukan Encoding dan Decoding URL UTF8 dalam VB6, dengan memanfaatkan OCX Microsoft Script Control. Adapun kode untuk Encode dan Decode URL UTF8 menggunakan Visual Basic 6.0 adalah sebagai berikut:
'=================================================================
'UrlEncodeUtf8 menggunakan Script Control
'=================================================================
Public Function UrlEncodeUtf8(ByRef strSource As String) As String
Dim sc As Object
Set sc = CreateObject("ScriptControl")
sc.Language = "Jscript"
UrlEncodeUtf8 = sc.CodeObject.encodeURIComponent(strSource)
Set sc = Nothing
End Function

'=================================================================
'UrlDecodeUtf8 menggunakan Script Control
'=================================================================
Public Function URLDecodeUTF8(strSource As String) As String
Dim sc As Object
Set sc = CreateObject("ScriptControl")
sc.Language = "Jscript"
URLDecodeUTF8 = sc.CodeObject.decodeURIComponent(strSource)
Set sc = Nothing
End Function
READ MORE - URL Encode - Decode UTF8 Menggunakan Script Control

VB6 Code - Mencari seluruh Printer Port

Lebih tepatnya mencari port printer tertentu dari seluruh printer port yang ada menggunakan kode VB6. Adapun kode VB6 untuk mencari port tertentu dari seluruh printer port yang ada adalah sebagai berikut:
Public Function FindPrinterPort(Port As String) As Boolean

Dim P As Printer, Found As Boolean
For Each P In Printers
If Printer.Port = Port & ":" Then
Found = True
Exit For
End If
Next

FindPrinterPort = Found

End Function
Demikian VB6 kode untuk mencari port tertentu dari seluruh printer port yang ada.
READ MORE - VB6 Code - Mencari seluruh Printer Port

VB6 Code - Menampilkan Dialog Page Setup

Option Explicit

Private Sub Command1_Click()
With CommonDialog1
.Flags = CommonDialog1.Flags Or PrinterConstants.cdlPDPrintSetup
.CancelError = True
On Error Resume Next
Call .ShowPrinter
If Err.Number <> ErrorConstants.cdlCancel Then
Call MsgBox("here, please implement the process after the end of the printer settings")
End If
End With
End Sub
READ MORE - VB6 Code - Menampilkan Dialog Page Setup

VB6 Code - Memperoleh Control Yang Sedang Aktif - Focus

Option Explicit

Private Sub Timer1_Timer()
Dim cControl As Control
Set cControl = Me.ActiveControl

If Not cControl Is Nothing Then
Caption = cControl.Name
End If
End Sub

READ MORE - VB6 Code - Memperoleh Control Yang Sedang Aktif - Focus

Contoh Menggunakan CommonDialog Open Save As

'Contoh untuk CommonDialog Open
Private Sub Command1_Click()

On Error GoTo ErrHandler

Dim strPath As String

With CommonDialog1
.CancelError = True
.Flags = cdlOFNHideReadOnly
.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
.FilterIndex = 2
.DialogTitle = "Open File"
.ShowOpen
strPath = .FileName
End With
'Code selanjutnya
Exit Sub

ErrHandler:

Exit Sub

End Sub

'Contoh untuk CommonDialog Save As
Private Sub Command2_Click()

On Error GoTo ErrHandler

Dim strPath As String

With CommonDialog1
.CancelError = True
.Flags = cdlOFNHideReadOnly
.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
.FilterIndex = 2
.DialogTitle = "Save As"
.ShowSave
strPath = .FileName
End With
'Code selanjutnya
Exit Sub

ErrHandler:

Exit Sub
End Sub

'Contoh untuk CommonDialog Save
Private Sub Command3_Click()

On Error GoTo ErrHandler

Dim strPath As String

With CommonDialog1
.CancelError = True
.Flags = cdlOFNHideReadOnly
.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
.FilterIndex = 2
.DialogTitle = "Save"
.ShowSave
strPath = .FileName
End With
'Code selanjutnya
Exit Sub

ErrHandler:

Exit Sub
End Sub
READ MORE - Contoh Menggunakan CommonDialog Open Save As

Membaca File Binary Dengan Visual Basic 6.0

Option Explicit

Private Sub Command1_Click()
Open "C:\Documents and Settings\Admin\My Documents\Blogger VB6\Blogger\4basic-vb.xml" For Binary As #1
Dim strBuff As String
strBuff = Space(LOF(1))
Get #1, , strBuff
Close #1
Text1.Text = strBuff
End Sub
READ MORE - Membaca File Binary Dengan Visual Basic 6.0

XML Pretty Print - Merapikan Format File XML

Private Sub PrettyPrint(Parent As IXMLDOMNode, Optional Level As Integer)
Dim Node As IXMLDOMNode
Dim Indent As IXMLDOMText

If Not Parent.ParentNode Is Nothing And Parent.ChildNodes.Length > 0 Then
For Each Node In Parent.ChildNodes
Set Indent = Node.OwnerDocument.createTextNode(vbNewLine & String(Level, vbTab))

If Node.NodeType = NODE_TEXT Then
If Trim(Node.Text) = "" Then
Parent.RemoveChild Node
End If
ElseIf Node.PreviousSibling Is Nothing Then
Parent.InsertBefore Indent, Node
ElseIf Node.PreviousSibling.NodeType <> NODE_TEXT Then
Parent.InsertBefore Indent, Node
End If
Next Node
End If

If Parent.ChildNodes.Length > 0 Then
For Each Node In Parent.ChildNodes
If Node.NodeType <> NODE_TEXT Then PrettyPrint Node, Level + 1
Next Node
End If
End Sub
READ MORE - XML Pretty Print - Merapikan Format File XML

XML Tidy - Untuk Merapikan File XML

Public Function PrettyPrintXML(XML As String) As String

Dim Reader As New SAXXMLReader60
Dim Writer As New MXXMLWriter60

Writer.Indent = True
Writer.standalone = False
Writer.omitXMLDeclaration = False
Writer.encoding = "utf-8"

Set Reader.contentHandler = Writer
Set Reader.dtdHandler = Writer
Set Reader.errorHandler = Writer

Call Reader.putProperty("http://xml.org/sax/properties/declaration-handler", _
Writer)
Call Reader.putProperty("http://xml.org/sax/properties/lexical-handler", _
Writer)

Call Reader.parse(XML)

PrettyPrintXML = Writer.output

End Function

Public Function PrettyPrintDocument(Doc As DOMDocument60) As String
PrettyPrintDocument = PrettyPrintXML(Doc.XML)
End Function
READ MORE - XML Tidy - Untuk Merapikan File XML

Memperoleh Informasi Time Zone Dari Local Time

Option Explicit

Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Function GetTimeZone() As String
Dim tzInfo As TIME_ZONE_INFORMATION
Dim s As String
GetTimeZoneInformation tzInfo
s = IIf(tzInfo.Bias < 0, "+", "-")
GetTimeZone = s & Format((Abs(tzInfo.Bias) \ 60) & ":" & (Abs(tzInfo.Bias) Mod 60), "hh:mm")
End Function

Private Sub Command1_Click()
MsgBox GetTimeZone
End Sub
READ MORE - Memperoleh Informasi Time Zone Dari Local Time

Encode Decode Base64 Menggunakan MSXML

Public Function Base64Enc(ByRef vxbData() As Byte) As String
With CreateObject("MSXML.DOMDocument").CreateElement(" Base64 ")
.DataType = "bin.base64"
.NodeTypedValue = vxbData
Base64Enc = .Text
End With
End Function

Public Function Base64Dec(ByRef vsData As String) As Byte()
With CreateObject("MSXML.DOMDocument").CreateElement("Base64")
.DataType = "bin.base64"
.Text = vsData
Base64Dec = .NodeTypedValue
End With
End Function
READ MORE - Encode Decode Base64 Menggunakan MSXML

Mengkopi Gambar Ke Clipboard Melalui VB6

Private Sub CopyFromPictureBox(pic As PictureBox)
With Clipboard
.Clear
.SetData pic.Picture
End With
End Sub

Private Sub CopyFromFile(Path As String)
With Clipboard
.Clear
.SetData LoadPicture(Path)
End With
End Sub
READ MORE - Mengkopi Gambar Ke Clipboard Melalui VB6

Progress Bar dari PictureBox Seperti Pada VB Classic

Option Explicit

Dim tenth As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Sub UpdateStatus(FileBytes As Long)
Static progress As Long
Dim r As Long
Const SRCCOPY = &HCC0020
Dim Txt$
progress = progress + FileBytes
If progress > Picture1.ScaleWidth Then
progress = Picture1.ScaleWidth
End If
Txt$ = Format$(CLng((progress / Picture1.ScaleWidth) * 100)) + "%"
Picture1.Cls
Picture1.CurrentX = (Picture1.ScaleWidth - Picture1.TextWidth(Txt$)) \ 2
Picture1.CurrentY = (Picture1.ScaleHeight - Picture1.TextHeight(Txt$)) \ 2
Picture1.Print Txt$
Picture1.Line (0, 0)-(progress, Picture1.ScaleHeight), Picture1.ForeColor, BF
r = BitBlt(Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, SRCCOPY)
End Sub

Private Sub Command1_Click()
Dim i As Integer, x As Long
Picture1.ScaleWidth = 109
tenth = 10
For i = 1 To 11
Call UpdateStatus(tenth)
x = Timer
While Timer < x + 0.75
DoEvents
Wend
Next
End Sub

Private Sub Form_Load()
Picture1.FontBold = True
Picture1.AutoRedraw = True
Picture1.BackColor = vbWhite
Picture1.DrawMode = 10
Picture1.FillStyle = 0
Picture1.ForeColor = vbBlue
End Sub
READ MORE - Progress Bar dari PictureBox Seperti Pada VB Classic

Cara Mudah Baca File Dan Menyimpannya Dalam Array

Option Explicit

Private Sub Command1_Click()
Dim strArray() As String
Open "c:\autoexec.bat" For Input As #1
strArray = Split(Input(LOF(1), 1), vbCrLf)
Close #1
End Sub
READ MORE - Cara Mudah Baca File Dan Menyimpannya Dalam Array

Tutorial File - Membaca, Menghapus Baris Tertentu, dsb

'Kode ini dibuat oleh plenderj salah satu member VBForums
'http://www.vbforums.com/showthread.php?s=&threadid=132171

' Clear the contents of a file
Private Sub clearFile(ByVal strPath As String)
If Not Len(Dir(strPath)) = 0 Then
Open strPath For Output As #1
Close #1
End If
End Sub

' Is a given string contained within a given file ?
Private Function isStringInFile(ByVal strString As String, ByVal strFile As String) As Boolean
isStringInFile = InStr(returnContents(strFile), strString) <> 0
End Function

' Delete a specific line from a file (note: first line = line number 0)
Private Sub deleteLine(ByVal strFile As String, ByVal lineNumber As Long)
Dim strArrBuff() As String, i As Long
Open strFile For Input As #1
strArrBuff() = Split(Input(LOF(1), 1), vbCrLf)
Close #1
Open strFile For Output As #1
For i = 0 To UBound(strArrBuff)
If Not i = lineNumber Then Print #1, strArrBuff(i)
Next
Close #1
End Sub

' Return a specific line number from a file (note: first line = line number 0)
Private Function getLine(ByVal strFile As String, ByVal lineNumber As Long) As String
Open strFile For Input As #1
getLine = Split(Input(LOF(1), 1), vbCrLf)(lineNumber)
Close #1
End Function

' Append a line to the end of a file
Private Sub appendLine(ByVal strFile As String, ByVal strLineOfText As String)
Open strFile For Append As #1
Print #1, strLineOfText
Close #1
End Sub

' Insert a line of text in a file
Private Sub insertLine(ByVal strFile As String, ByVal lineNumber As Long, ByVal strLineOfText As String)
Dim strBuff() As String: strBuff = Split(returnContents(strFile), vbCrLf)
Dim i As Long
Open strFile For Output As #1
For i = 0 To UBound(strBuff)
If i = lineNumber Then Print #1, strLineOfText
Print #1, strBuff(i)
Next
Close #1
End Sub

' Insert a string of text in a file
Private Sub insertString(ByVal strFile As String, ByVal writePosition As Long, ByVal strStringOfText As String)
Dim strBuff As String: strBuff = returnContents(strFile)
Open strFile For Output As #1
Print #1, Left(strBuff, writePosition) & strStringOfText & Mid(strBuff, writePosition)
Close #1
End Sub

' Return the contents of a file
Private Function returnContents(ByVal strFile As String) As String
Open strFile For Input As #1
returnContents = Input(LOF(1), 1)
Close #1
End Function

' Return the path of a given full path to a file
Private Function returnPathOfFile(ByVal strFile As String) As String
returnPathOfFile = Left(strFile, InStrRev(strFile, "\"))
End Function

' Return the filename of a given full path to a file
Private Function returnNameOfFile(ByVal strFile As String) As String
returnNameOfFile = Mid(strFile, InStrRev(strFile, "\") + 1)
End Function

' Split a file up into n byte chunks
Private Sub splitUpFile(ByVal strFile As String, ByVal nByteSize As Long)
Dim strBuff As String: strBuff = returnContents(strFile)
Dim currPos As Long, endPos As Long: currPos = 1: endPos = Len(strBuff)
Dim fileNumber As Long
While currPos <= endPos
Open Left(strFile, InStrRev(strFile, ".") - 1) & "(" & fileNumber & ")" & Mid(strFile, InStrRev(strFile, ".")) For Output As #1
If (currPos + nByteSize) > endPos Then
Print #1, Mid(strBuff, currPos)
Else
Print #1, Mid(strBuff, currPos, nByteSize)
End If
Close #1
fileNumber = fileNumber + 1
currPos = currPos + nByteSize
Wend
End Sub

' Merge a number of source files into a destination file
Private Sub mergeFiles(ByVal strDestinationFile As String, ParamArray strSourceFiles())
Dim i As Long, strBuff As String
Open strDestinationFile For Output As #1
For i = 0 To UBound(strSourceFiles)
Print #1, ""
Print #1, "***"
Print #1, "*** " & strSourceFiles(i)
Print #1, "***"
Print #1, returnContents(strSourceFiles(i))
Next
Close #1
End Sub
READ MORE - Tutorial File - Membaca, Menghapus Baris Tertentu, dsb

Membaca File Dan Memasukannya Ke Dalam Array

Option Explicit

Private Sub Command1_Click()

Dim L As Long
Dim MyArray() As String

' Load file into string array
FileToArray "C:\TEST.txt", MyArray

' Reverse array contents
ReverseStrArray MyArray

' show result in immediate window
For L = 0 To UBound(MyArray)
Debug.Print MyArray(L)
Next L

End Sub

Private Sub FileToArray(ByVal sPath As String, ByRef sArray() As String)
Dim ff As Integer
ff = FreeFile
On Error GoTo Fini
Open sPath For Input As #ff
sArray = Split(Input(LOF(ff), ff), vbCrLf)
Fini:
Close #ff
End Sub

Private Sub ReverseStrArray(ByRef sArray() As String)
Dim ubnd As Long, lbnd As Long, x As Long
Dim sTmp As String
ubnd = UBound(sArray)
lbnd = LBound(sArray)
For x = lbnd To ((ubnd - lbnd - 1) \ 2)
sTmp = sArray(lbnd + x)
sArray(lbnd + x) = sArray(ubnd - x)
sArray(ubnd - x) = sTmp
Next x
End Sub
READ MORE - Membaca File Dan Memasukannya Ke Dalam Array

Mengakses Element WebBrowser Dari Visual Basic 6.0

Option Explicit

Private Sub cmdBack_Click()
On Error Resume Next
WebBrowser1.GoBack
End Sub

Private Sub cmdForward_Click()
On Error Resume Next
WebBrowser1.GoForward
End Sub

Private Sub cmdGo_Click()
WebBrowser1.Navigate txtAddress
End Sub

Private Sub Form_Load()
WebBrowser1.Navigate "http://www.microsoft.com"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)

On Error Resume Next
If (pDisp Is WebBrowser1.object) Then

txtAddress = WebBrowser1.LocationURL
Me.Caption = WebBrowser1.LocationName
txtText = ""
tvTreeView.Nodes.Clear
RecurseFrames WebBrowser1.Document, Nothing
End If
End Sub

Private Sub RecurseFrames(ByVal iDoc As HTMLDocument, ByVal iNode As node)
Dim I As Integer
Dim Range As IHTMLTxtRange
Dim Title As String
Dim TextInfo As String
Dim tvNode As node

On Error Resume Next

Title = iDoc.Title
If Title = "" Then
Title = iDoc.parentWindow.Name
If Title = "" Then Title = iDoc.location
End If

If iNode Is Nothing Then
Set tvNode = tvTreeView.Nodes.Add(, , , Title)
Else
Set tvNode = tvTreeView.Nodes.Add(iNode.Index, tvwChild, , Title)
End If

TextInfo = "Frame: " & Title & vbCrLf & "{" + vbCrLf

If iDoc.body.tagName = "BODY" Then
FillTree iDoc, "OBJECT", tvNode, "ActiveX Controls"
FillTree iDoc, "A", tvNode, "Anchors"
FillTree iDoc, "IMG", tvNode, "Images"
FillTree iDoc, "", tvNode, "All"

Set Range = iDoc.body.createTextRange
TextInfo = TextInfo & Range.Text & vbCrLf
Set Range = Nothing
ElseIf iDoc.frames.length > 0 Then
For I = 0 To iDoc.frames.length - 1
TextInfo = TextInfo & "FRAME: " & iDoc.frames(I).Document.nameProp & vbCrLf
Dim doc As New HTMLDocument
Dim eCollection As IHTMLElementCollection
Dim uElement As HTMLUnknownElement
Set eCollection = iDoc.frames(I).Document.All
For Each uElement In eCollection
If uElement.tagName = "HTML" Then
doc.All(0).insertAdjacentHTML "BeforeBegin", uElement.innerHTML
doc.Title = "Frame: " & iDoc.frames(I).Document.nameProp
FillTree doc, "FRAME", tvNode, "FRAME"
RecurseFrames doc, tvNode
Set doc = Nothing
End If
Next uElement
Next I
End If

txtText.Text = txtText.Text & TextInfo & "}" & vbCrLf

End Sub

Private Sub FillTree(iDoc As HTMLDocument, iMatchTag As String, iNode As node, iCategory As String)
Dim Element As Object
Dim Info As String
Dim tvNode As node
Dim tvCatNode As node

On Error Resume Next

Set tvCatNode = Nothing
For Each Element In iDoc.All
If iMatchTag = "" Or Element.tagName = iMatchTag Then

Info = Element.tagName & " "

If Element.tagName = "IMG" Then
Info = Info & Element.href
ElseIf Element.tagName = "A" Then
Info = Info & Element.innerText & " (" & Element.href & ")"
ElseIf Element.tagName = "INPUT" Then
Info = Info & Element.Type
ElseIf Element.tagName = "META" Then
Info = Info & Element.nodeName
ElseIf Element.tagName = "FRAMESET" Then
Info = Info & Element.Name
ElseIf Element.tagName = "FRAME" Then
Info = Info & ": " & Element.src
Else
Info = Info & Element.Id
End If

If tvCatNode Is Nothing Then
Set tvCatNode = tvTreeView.Nodes.Add(iNode.Index, tvwChild, , iCategory)
End If
Set tvNode = tvTreeView.Nodes.Add(tvCatNode.Index, tvwChild, , Info)
End If
If Element.tagName = "FRAME" Then
Dim I As Long
For I = 0 To iDoc.frames.length - 1
If iDoc.frames(I).Document.nameProp = Element.Document.nameProp Then
Dim doc As New HTMLDocument
Dim eCollection As IHTMLElementCollection
Dim uElement As HTMLUnknownElement
Set eCollection = iDoc.frames(I).Document.All
For Each uElement In eCollection
If uElement.tagName = "HTML" Then
doc.All(0).insertAdjacentHTML "BeforeBegin", uElement.innerHTML
doc.Title = "Frame: " & iDoc.frames(I).Document.nameProp
RecurseFrames doc, tvNode
Set doc = Nothing
End If
Next uElement
End If
Next I
End If
Next
End Sub
READ MORE - Mengakses Element WebBrowser Dari Visual Basic 6.0

Membaca File Binary atau Text Dengan Cepat

'Kode ini dibuat oleh plenderj salah satu member VBForums
'http://www.vbforums.com/showthread.php?s=&threadid=132171

' Return a specific line number from a file (note: first line = line number 0)
Private Function getLine(ByVal strFile As String, ByVal lineNumber As Long) As String
Dim strBuff As String
Open strFile For Binary As #1
strBuff = Space(LOF(1))
Get #1, , strBuff
getLine = Split(strBuff, vbCrLf)(lineNumber)
Close #1
End Function

' Return a specific line number from a file (note: first line = line number 0) - a neater version.
Private Function getLine(ByVal strFile As String, ByVal lineNumber As Long) As String
getLine = Split(returnContents(strFile), vbCrLf)(lineNumber)
End Function

' Delete a specific line from a file (note: first line = line number 0)
Private Sub deleteLine(ByVal strFile As String, ByVal lineNumber As Long)
Dim strArrBuff() As String, i As Long, strFileContent As String
strArrBuff() = Split(returnContents(strFile), vbCrLf)
strArrBuff(lineNumber) = vbNullString
Open strFile For Output As #1
Print #1, Join(strArrBuff, vbCrLf);
Close #1
End Sub

' Return the contents of a file
Private Function returnContents(ByVal strFile As String) As String
Dim strBuff As String
Open strFile For Binary As #1
strBuff = Space(LOF(1))
Get #1, , strBuff
returnContents = strBuff
Close #1
End Function
READ MORE - Membaca File Binary atau Text Dengan Cepat

Custom File Untuk Keperluan Import Database

''Gunakan editor terbaik dari Microsoft yakni Notepad
''Tulis seperti di bawah ini
'1, Description 1 ,1,100.00,3/1/1998
'2, Description 2 ,2,200.00,3/2/1998
'Simpan dengan nama c:\test.txt.

Private Sub Command1_Click()
Dim F As Long, sLine As String, A(0 To 4) As String
Dim db As Database, rs As Recordset
F = FreeFile
Open "c:\test.txt" For Input As F
Set db = CurrentDb
Set db = DBEngine(0).OpenDatabase("biblio.mdb")
On Error Resume Next
db.Execute "DROP TABLE TestImport"
On Error GoTo 0
db.Execute "CREATE TABLE TestImport (ID LONG, [Desc] TEXT (50), " & "Qty LONG, Cost CURRENCY, OrdDate DATETIME)"
Set rs = db.OpenRecordset("TestImport", dbOpenTable)
Do While Not EOF(F)
Line Input #F, sLine
ParseToArray sLine, A()
rs.AddNew
rs(0) = Val(A(0))
rs(1) = A(1)
rs(2) = Val(A(2))
rs(3) = Val(A(3))
rs(4) = CDate(A(4))
rs.Update
Loop
rs.Close
db.Close
Close #F
End Sub

Sub ParseToArray(sLine As String, A() As String)
Dim P As Long, LastPos As Long, I As Long
P = InStr(sLine, ",")
Do While P
A(I) = Mid$(sLine, LastPos + 1, P - LastPos - 1)
LastPos = P
I = I + 1
P = InStr(LastPos + 1, sLine, ",", vbBinaryCompare)
Loop
A(I) = Mid$(sLine, LastPos + 1)
End Sub
READ MORE - Custom File Untuk Keperluan Import Database

Membaca dan Menampilkan Karakter Unicode

Option Explicit

Private Sub Command1_Click()
Dim a(0 To 5) As Byte
a(0) = &HFF
a(1) = &HFE
a(2) = &H39
a(3) = &H4E
a(4) = &H44
a(5) = &H0
Open "unicode.txt" For Binary As #1
Put #1, , a
Close #1
End Sub

Private Sub Command2_Click()
Dim txtline As String

Open "unicode.txt" For Binary As #1
txtline = InputB(2, #1)
txtline = InputB(4, #1)
Close #1

TextBox1.Text = txtline
End Sub
READ MORE - Membaca dan Menampilkan Karakter Unicode

TAB Karakter Pada RichTextBox Control

Private Sub RichTextBox1_GotFocus()
ReDim arrTabStop(0 To Controls.Count - 1) As Boolean
For I = 0 To Controls.Count - 1
arrTabStop(I) = Controls(I).TabStop
Controls(I).TabStop = False
Next
End Sub

Private Sub RichTextBox1_LostFocus()
For I = 0 To Controls.Count - 1
Controls(I).TabStop = arrTabStop(I)
Next
End Sub
READ MORE - TAB Karakter Pada RichTextBox Control

Implementasi Pencarian Pada RichTextBox Control

Option Explicit

Private Sub Command1_Click()
HighlightWords RichTextBox1, "text", vbRed
End Sub

Private Function HighlightWords(rtb As RichTextBox, sFindString As String, lColor As Long) As Integer

Dim lFoundPos As Long
Dim lFindLength As Long
Dim lOriginalSelStart As Long
Dim lOriginalSelLength As Long
Dim iMatchCount As Integer

lOriginalSelStart = rtb.SelStart
lOriginalSelLength = rtb.SelLength

lFindLength = Len(sFindString)

lFoundPos = rtb.Find(sFindString, 0, , rtfNoHighlight)
While lFoundPos > 0
iMatchCount = iMatchCount + 1

rtb.SelStart = lFoundPos
rtb.SelLength = lFindLength
rtb.SelColor = lColor

lFoundPos = rtb.Find(sFindString, lFoundPos + lFindLength, , rtfNoHighlight)
Wend

rtb.SelStart = lOriginalSelStart
rtb.SelLength = lOriginalSelLength

HighlightWords = iMatchCount

End Function
READ MORE - Implementasi Pencarian Pada RichTextBox Control

Scroll Treeview Ketika Sedang Drag And Drop Sebuah Node

Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Dim mfX As Single
Dim mfY As Single
Dim moNode As node
Dim m_iScrollDir As Integer
Dim mbFlag As Boolean

Private Sub Form_DragOver(Source As Control, x As Single, y As Single, State As Integer)
If Source.Name = "TreeView1" Then
Timer1.Enabled = False
End If
End Sub

Private Sub Form_Load()
Dim i As Integer
Dim n As Integer
Timer1.Enabled = False
Timer1.Interval = 200
TreeView1.Style = tvwTreelinesPlusMinusPictureText
TreeView1.ImageList = ImageList1
For i = 1 To 50
TreeView1.Nodes.Add Text:="Node " & i, Image:=1, SelectedImage:=2
Next i
For i = 1 To 50
For n = 1 To 5
TreeView1.Nodes.Add Relative:=i, Relationship:=tvwChild, Text:="Child Node " & n, Image:=1, SelectedImage:=2
Next n
Next i
End Sub

Private Sub Timer1_Timer()
Set TreeView1.DropHighlight = TreeView1.HitTest(mfX, mfY)
If m_iScrollDir = -1 Then
SendMessage TreeView1.hwnd, 277&, 0&, vbNull
Else
SendMessage TreeView1.hwnd, 277&, 1&, vbNull
End If
End Sub

Private Sub TreeView1_DragDrop(Source As Control, x As Single, y As Single)
If Not TreeView1.DropHighlight Is Nothing Then
MsgBox moNode.Text & " was dropped on " & TreeView1.DropHighlight.Text
End If
Set TreeView1.DropHighlight = Nothing
Set moNode = Nothing
Timer1.Enabled = False
End Sub

Private Sub TreeView1_DragOver(Source As Control, x As Single, y As Single, State As Integer)
Set TreeView1.DropHighlight = TreeView1.HitTest(x, y)
mfX = x
mfY = y
If y > 0 And y < 100 Then
m_iScrollDir = -1
Timer1.Enabled = True
ElseIf y > (TreeView1.Height - 200) And y < TreeView1.Height Then
m_iScrollDir = 1
Timer1.Enabled = True
Else
Timer1.Enabled = False
End If
End Sub

Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Timer1.Enabled = False
End Sub

Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
TreeView1.DropHighlight = TreeView1.HitTest(x, y)
If Not TreeView1.DropHighlight Is Nothing Then
TreeView1.SelectedItem = TreeView1.HitTest(x, y)
Set moNode = TreeView1.SelectedItem
End If
Set TreeView1.DropHighlight = Nothing
End Sub

Private Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
TreeView1.DragIcon = TreeView1.SelectedItem.CreateDragImage
TreeView1.Drag vbBeginDrag
End If
End Sub
READ MORE - Scroll Treeview Ketika Sedang Drag And Drop Sebuah Node

Membuat Random Auto Number - DAO

Public Sub CreateRandomAutonumber()
Dim db As DAO.Database
Dim td As DAO.TableDef
Dim f As DAO.field

Set db = CurrentDb
Set td = db.CreateTableDef("Table1")
Set f = td.CreateField("MyAutoNumber")

f.Type = dbLong
f.Attributes = dbAutoIncrField
td.Fields.Append f

Set f = td.CreateField("MyTextField")
f.Type = dbText
td.Fields.Append f
db.TableDefs.Append td
td.Fields("MyAutoNumber").DefaultValue = "GenUniqueID()"
Application.RefreshDatabaseWindow
End Sub
READ MORE - Membuat Random Auto Number - DAO

Memperoleh Icon Asosiasi File Menggunakan SHFileInfo

Option Explicit

Private Const SHGFI_DISPLAYNAME = &H200
Private Const SHGFI_EXETYPE = &H2000
Private Const SHGFI_SYSICONINDEX = &H4000
Private Const SHGFI_LARGEICON = &H0
Private Const SHGFI_SMALLICON = &H1
Private Const ILD_TRANSPARENT = &H1
Private Const SHGFI_SHELLICONSIZE = &H4
Private Const SHGFI_TYPENAME = &H400
Private Const BASIC_SHGFI_FLAGS = SHGFI_TYPENAME Or SHGFI_SHELLICONSIZE Or SHGFI_SYSICONINDEX Or SHGFI_DISPLAYNAME Or SHGFI_EXETYPE

Private Const MAX_PATH = 260

Private Type SHFILEINFO
hIcon As Long
iIcon As Long
dwAttributes As Long
szDisplayName As String * MAX_PATH
szTypeName As String * 80
End Type

Private Declare Function ImageList_Draw Lib "comctl32.dll" (ByVal himl As Long, ByVal i As Long, ByVal hDCDest As Long, ByVal x As Long, ByVal y As Long, ByVal flags As Long) As Long
Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbSizeFileInfo As Long, ByVal uFlags As Long) As Long

Private Sub Form_Load()
With picDummyPictureBox
.AutoRedraw = True
.AutoSize = True
.Height = 495
.Width = 495
.Appearance = 0
.Visible = False
End With

With picInvisiblePictureBox
.AutoRedraw = True
.AutoSize = True
.Height = 495
.Width = 495
.Appearance = 0
.Visible = False
End With

rtBox.OLEDropMode = rtfOLEDropManual

picDummyPictureBox.Picture = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Flags\flgusa01.ico")

Set lvFileList.SmallIcons = Nothing
ilImages.ListImages.Clear
ilImages.ListImages.Add , "dummy", picDummyPictureBox.Picture
Set lvFileList.Icons = ilImages
End Sub

Private Sub rtBox_OLEDragDrop(Data As RichTextLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)

Dim nCounter As Integer
Dim lBoundary As Long

For nCounter = 1 To Data.Files.Count
StickIconOntoListView Data.Files(nCounter)
Next nCounter
End Sub

Private Sub StickIconOntoListView(strFile As String)

Dim hImgLarge As Long
Dim hFile As Long
Dim strFileType As String
Dim strListImageKey As String
Dim imgX As ListImage
Dim hEXEType As Long
Dim tEXEType As Long
Dim lRet As Long
Dim itmX As ListItem
Dim shinfo As SHFILEINFO

hImgLarge = SHGetFileInfo(strFile, 0&, shinfo, Len(shinfo), BASIC_SHGFI_FLAGS Or SHGFI_LARGEICON)

strFileType = LCase(StripNulls(shinfo.szTypeName))

If hImgLarge > 0 Then
lRet = vbAddFileItemIcon(hImgLarge, shinfo)

Set imgX = ilImages.ListImages.Add(, strFile, picInvisiblePictureBox.Picture)
strListImageKey = strFile
Else
End If

Set itmX = lvFileList.ListItems.Add(, , LCase(strFile))
itmX.Icon = ilImages.ListImages(strListImageKey).Key

Set itmX = Nothing
End Sub

Private Function vbAddFileItemIcon(hImage As Long, sInfo As SHFILEINFO) As Long

Dim lRet As Long

picInvisiblePictureBox.Picture = LoadPicture()
lRet = ImageList_Draw(hImage, sInfo.iIcon, picInvisiblePictureBox.hdc, 0, 0, ILD_TRANSPARENT)

picInvisiblePictureBox.Picture = picInvisiblePictureBox.Image
picInvisiblePictureBox.Height = 495
picInvisiblePictureBox.Width = 495

vbAddFileItemIcon = lRet
End Function

Private Function StripNulls(strItem As String) As String

Dim nPos As Integer

nPos = InStr(strItem, Chr$(0))
If nPos Then
strItem = Left$(strItem, nPos - 1)
End If
StripNulls = strItem
End Function
READ MORE - Memperoleh Icon Asosiasi File Menggunakan SHFileInfo

Apakah ScrollBar Visible Pada Sebuah Control?

Option Explicit

Private Const GWL_STYLE = (-16)
Private Const WS_HSCROLL = &H100000
Private Const WS_VSCROLL = &H200000

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Sub Command1_Click()
Dim wndStyle As Long
wndStyle = GetWindowLong(TreeView1.hwnd, GWL_STYLE)
If (wndStyle And WS_HSCROLL) <> 0 Then
MsgBox "A horizontal scroll bar is visible."
Else
MsgBox "A horizontal scroll bar is NOT visible."
End If

If (wndStyle And WS_VSCROLL) <> 0 Then
MsgBox "A vertical scroll bar is visible."
Else
MsgBox "A vertical scroll bar is NOT visible."
End If
End Sub

Private Sub Command2_Click()
TreeView1.Move 250, 900, 1000, 1000
End Sub

Private Sub Form_Load()
Form1.ScaleMode = 1
Form1.Move 0, 0, 5100, 5040
Command1.Caption = "Scroll Bar Test"
Command1.Move 120, 120, 1700, 500
Command2.Caption = "Size Control"
Command2.Move 2000, 120, 1700, 500
TreeView1.Move 250, 900, 3000, 1500
TreeView1.Nodes.Add , , , "1: Sample Text"
TreeView1.Nodes.Add , , , "2: Sample Text"
TreeView1.Nodes.Add , , , "3: Sample Text"
TreeView1.Nodes.Add , , , "4: Sample Text"
End Sub
READ MORE - Apakah ScrollBar Visible Pada Sebuah Control?

Bagaimana Cara Mem-Print RichTextBox Yang Memiliki Image

Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4&
Private Const PRF_CHILDREN = &H10&
Private Const PRF_OWNED = &H20&

Private Sub Command1_Click()
RichTextBox1.OLEObjects.Add , , "c:\windows\triangles.bmp"
End Sub

Private Sub Command2_Click()
Dim rv As Long
Picture1.SetFocus
Picture2.AutoRedraw = True
rv = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hdc, 0)
rv = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hdc, PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
Picture2.Picture = Picture2.Image
Picture2.AutoRedraw = False
Command1.SetFocus
End Sub

Private Sub Command3_Click()
Printer.PaintPicture Picture2.Picture, 0, 0
Printer.EndDoc
End Sub
READ MORE - Bagaimana Cara Mem-Print RichTextBox Yang Memiliki Image

Pencarian Secara Recursive Pada RichTextBox

Private Sub Form_Load()

RichTextBox1.LoadFile "license.txt"

End Sub

Private Sub Command1_Click()

Dim strval As String
Dim nStrings As Long

RichTextBox1.LoadFile "license.txt"

strval = " " & InputBox("Enter the string to find.", "Findit", "the") & " "

If strval <> "" Then

nStrings = FindIt(RichTextBox1, strval)
MsgBox (Str$(nStrings) & " instances found.")
End If

End Sub

Private Function FindIt(Box As RichTextBox, Srch As String, Optional Start As Long)

Dim retval As Long
Dim Source As String

Source = Box.Text

If Start = 0 Then Start = 1

retval = InStr(Start, Source, Srch)

If retval <> 0 Then

With Box
.SelStart = retval - 1
.SelLength = Len(Srch)
.SelColor = vbRed
.SelBold = True
.SelLength = 0
End With

Start = retval + Len(Srch)

FindIt = 1 + FindIt(Box, Srch, Start)
End If
End Function
READ MORE - Pencarian Secara Recursive Pada RichTextBox

Bermain Dengan Horizontal Vertical Scroll TextBox

Option Explicit

Const EM_LINESCROLL = &HB6

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Long) As Long

Private Sub Form_Load()
Dim intLineIndex As Integer, intWordIndex As Integer

Text1.Font = "Courier New"
Text1.Text = ""
For intLineIndex = 1 To 25
Text1.Text = Text1.Text & "Line" & Str$(intLineIndex)
For intWordIndex = 1 To 5
Text1.Text = Text1.Text & " Word" & Str$(intWordIndex)
Next intWordIndex
Text1.Text = Text1.Text & vbCrLf
Next intLineIndex

Command1.Caption = "Vertical"
Command2.Caption = "Horizontal"
End Sub

Private Sub Command1_Click()
Dim lngRet As Long
lngRet = SendMessage(Text1.hWnd, EM_LINESCROLL, 0, 5&)
End Sub

Private Sub Command2_Click()
Dim lngRet As Long
lngRet = SendMessage(Text1.hWnd, EM_LINESCROLL, 5, 0&)
End Sub
READ MORE - Bermain Dengan Horizontal Vertical Scroll TextBox

Contoh CommonDialog - Print Dengan Range Tertentu

Option Explicit

Private Sub Command1_Click()
Dim myDatabase As Database
Dim rsMyTable As Recordset
Dim i As Integer
Dim j As Integer
Dim startpage As Integer

CommonDialog1.Max = 3
CommonDialog1.FromPage = 1
CommonDialog1.ToPage = 3
CommonDialog1.flags = 0
CommonDialog1.ShowPrinter
startpage = CommonDialog1.FromPage

Printer.FontSize = 18

Set myDatabase = OpenDatabase("nwind.mdb")
Set rsMyTable = myDatabase.OpenRecordset("Customers")

rsMyTable.MoveFirst

If (CommonDialog1.flags And cdlPDPageNums) <> 0 Then
MsgBox " Printing pages " & CommonDialog1.FromPage & " to " & CommonDialog1.ToPage
Select Case startpage
Case 1

Case 2
For i = 1 To 42
rsMyTable.MoveNext
Next

Case 3
For i = 1 To 84
rsMyTable.MoveNext
Next
End Select

If startpage <> 0 Then
For j = startpage To CommonDialog1.ToPage
For i = 1 To 42
If rsMyTable.EOF Then Exit For
Text1.Text = Text1.Text & rsMyTable!CompanyName & vbCrLf
Printer.Print rsMyTable!CompanyName
rsMyTable.MoveNext
Next
Printer.NewPage
Next
Printer.EndDoc
End If

ElseIf (CommonDialog1.flags And cdlPDSelection) <> 0 Then

rsMyTable.MoveLast
rsMyTable.MoveFirst
For i = 1 To rsMyTable.RecordCount
Text1.Text = Text1.Text & rsMyTable!CompanyName & vbCrLf
rsMyTable.MoveNext
Next
MsgBox "Select text to be printed"
Else
For i = 1 To rsMyTable.RecordCount
Text1.Text = Text1.Text & rsMyTable!CompanyName & vbCrLf
rsMyTable.MoveNext
Next
Printer.Print Text1.Text
Printer.EndDoc
MsgBox "Printing all pages"
End If
End Sub

Private Sub Command2_Click()
Printer.Print Text1.SelText
Printer.EndDoc
End Sub

Private Sub Form_Load()
Command1.Caption = "Select Printing Option"
Command2.Caption = "Print selected text"
End Sub
READ MORE - Contoh CommonDialog - Print Dengan Range Tertentu

Contoh MRU - Most Recently Used

Option Explicit

Private Const MaxMRU = 4
Private Const NotFound = -1
Private Const NoMRUs = -1

Private MRUCount As Long

Private Sub Form_Load()
MRUCount = NoMRUs

GetMRUFileList
End Sub

Private Sub Form_Unload(Cancel As Integer)
SaveMRUFileList
End Sub

Private Sub mnuMRU_Click(Index As Integer)
ReorderMRUList mnuMRU(Index).Caption, CLng(Index)
End Sub

Private Sub mnuOpen_Click()
Me.CommonDialog1.ShowOpen

AddMRUItem Me.CommonDialog1.FileName
End Sub

Private Sub AddMRUItem(NewItem As String)
Dim result As Long

result = CheckForDuplicateMRU(NewItem)

If result <> NotFound Then
ReorderMRUList NewItem, result
Else
AddMenuElement NewItem
End If
End Sub

Private Function CheckForDuplicateMRU(ByVal NewItem As String) As Long
Dim i As Long

NewItem = UCase$(NewItem)

For i = 0 To MRUCount
If UCase$(Me.mnuMRU(i).Caption) = NewItem Then
CheckForDuplicateMRU = i

Exit Function
End If
Next i

CheckForDuplicateMRU = -1
End Function

Private Sub mnuQuit_Click()
Unload Me
End Sub

Private Sub AddMenuElement(NewItem As String)
Dim i As Long

If (MRUCount < (MaxMRU - 1)) Or (MaxMRU = -1) Then
MRUCount = MRUCount + 1

If MRUCount <> 0 Then
Load mnuMRU(MRUCount)
End If

mnuMRU(MRUCount).Visible = True
End If

For i = (MRUCount) To 1 Step -1
mnuMRU(i).Caption = mnuMRU(i - 1).Caption
Next i

mnuMRU(0).Caption = NewItem
End Sub

Private Sub ReorderMRUList(DuplicateMRU As String, DuplicateLocation As Long)
Dim i As Long

For i = DuplicateLocation To 1 Step -1
mnuMRU(i).Caption = mnuMRU(i - 1).Caption
Next i

mnuMRU(0).Caption = DuplicateMRU
End Sub

Private Sub GetMRUFileList()
Dim i As Long
Dim result As String

Do
result = GetSetting(App.Title, "MRUFiles", Trim$(CStr(i)), "")

If result <> "" Then
AddMRUItem result
End If

i = i + 1
Loop Until (result = "")
End Sub

Private Sub SaveMRUFileList()
Dim i As Long

For i = 0 To MRUCount
SaveSetting App.Title, "MRUFiles", Trim$(CStr(i)), mnuMRU(i).Caption
Next i
End Sub
READ MORE - Contoh MRU - Most Recently Used

Contoh Mengisi ListView Dengan Database

Option Explicit

Function FillList(strDomain As String, objListView As Object) As Boolean
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim intTotCount As Integer
Dim intCount1 As Integer
Dim intCount2 As Integer
Dim colNew As ColumnHeader
Dim itmNewLine As ListItem

On Error GoTo Err_Handler

objListView.ListItems.Clear
objListView.ColumnHeaders.Clear

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strDomain)

For intCount1 = 0 To rst.Fields.Count - 1
Set colNew = objListView.ColumnHeaders.Add(, , rst(intCount1).Name)
Next intCount1

objListView.View = 3

rst.MoveLast
intTotCount = rst.RecordCount
rst.MoveFirst

For intCount1 = 1 To intTotCount
If IsNumeric(rst(0).Value) Then
Set itmNewLine = objListView.ListItems.Add(, , Str(rst(0).Value))
Else
Set itmNewLine = objListView.ListItems.Add(, , rst(0).Value)
End If

For intCount2 = 1 To rst.Fields.Count - 1
itmNewLine.SubItems(intCount2) = rst(intCount2).Value
Next intCount2

rst.MoveNext
Next intCount1

Exit Function

Err_Handler:
If Err = 94 Then
Resume Next
Else
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
End If
End Function

Private Sub Form_Load()
Dim intResult As Integer
intResult = FillList("Employees", Me!ctlListView)
End Sub
READ MORE - Contoh Mengisi ListView Dengan Database

Contoh Mengisi ListView Secara Recursive

Function FirstFileMatch()

Dim strFileName As String
On Error Resume Next

strFileName = Dir(InputBox("Enter a valid path and file name."))
If strFileName = "" Then
FirstFileMatch = FirstFileMatch()
Else
FirstFileMatch = strFileName
End If

End Function

Private Sub Form_Load()
Const strTableQueryName = "Employees"
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset(strTableQueryName, dbOpenDynaset, dbReadOnly)
AddBranch rst:=rst, strPointerField:="ReportsTo", strIDField:="EmployeeID", strTextField:="LastName"
End Sub

Sub AddBranch(rst As Recordset, strPointerField As String, strIDField As String, strTextField As String, Optional varReportToID As Variant)
On Error GoTo errAddBranch
Dim nodCurrent As node, objTree As TreeView
Dim strCriteria As String, strText As String, strKey As String
Dim nodParent As node, bk As String
Set objTree = Me!xTree.object
If IsMissing(varReportToID) Then
strCriteria = strPointerField & " Is Null"
Else
strCriteria = BuildCriteria(strPointerField, rst.Fields(strPointerField).Type, "=" & varReportToID)
Set nodParent = objTree.Nodes("a" & varReportToID)
End If

rst.FindFirst strCriteria
Do Until rst.NoMatch
strText = rst(strTextField)
strKey = "a" & rst(strIDField)
If Not IsMissing(varReportToID) Then
Set nodCurrent = objTree.Nodes.Add(nodParent, tvwChild, strKey, strText)
Else
Set nodCurrent = objTree.Nodes.Add(, , strKey, strText)
End If
bk = rst.Bookmark
AddBranch rst, strPointerField, strIDField, strTextField, rst(strIDField)
rst.Bookmark = bk
rst.FindNext strCriteria
Loop

exitAddBranch:
Exit Sub

errAddBranch:
MsgBox "Can"
Resume exitAddBranch
End Sub
READ MORE - Contoh Mengisi ListView Secara Recursive

Rename Node TreeView Seperti Pada Explorer

Option Explicit

Dim sNodeText As String

Private Sub Form_Load()
TreeView1.Nodes.Add , , , "test"
TreeView1.Nodes.Add , , , "test 1"
TreeView1.Nodes.Add , , , "test 2"
End Sub

Private Sub Timer1_Timer()
TreeView1.StartLabelEdit
Timer1.Enabled = False
End Sub

Private Sub TreeView1_AfterLabelEdit(Cancel As Integer, NewString As String)
If Len(NewString) < 1 Then
MsgBox "Error! You must enter a value"
Timer1.Interval = 100
Timer1.Enabled = True
End If
End Sub

Private Sub TreeView1_BeforeLabelEdit(Cancel As Integer)
If Len(TreeView1.SelectedItem.Text) > 0 Then
sNodeText = TreeView1.SelectedItem.Text
End If
End Sub

Private Sub TreeView1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then
TreeView1.SelectedItem.Text = sNodeText
End If
End Sub
READ MORE - Rename Node TreeView Seperti Pada Explorer

Mengubat BackGround TreeView Control

Option Explicit

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Const GWL_STYLE = -16&
Private Const TVM_SETBKCOLOR = 4381&
Private Const TVM_GETBKCOLOR = 4383&
Private Const TVS_HASLINES = 2&

Dim frmlastForm As Form

Private Sub Form_Load()
Dim nodX As node
Set nodX = TreeView1.Nodes.Add(, , "R", "Root")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C1", "Child 1")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C2", "Child 2")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C3", "Child 3")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C4", "Child 4")
nodX.EnsureVisible
TreeView1.Style = tvwTreelinesText
TreeView1.BorderStyle = vbFixedSingle
End Sub

Private Sub Command1_Click()
Dim lngStyle As Long
Call SendMessage(TreeView1.hWnd, TVM_SETBKCOLOR, 0, ByVal RGB(255, 0, 0))
lngStyle = GetWindowLong(TreeView1.hWnd, GWL_STYLE)
Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle - TVS_HASLINES)
Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle)
End Sub
READ MORE - Mengubat BackGround TreeView Control

Cara Membuat Generic Handler Error

Option Explicit

Private Sub Form_Load()
On Error GoTo FormLoadErr
Err.Raise 76
Err.Raise 70
Exit Sub

FormLoadErr:
Select Case Err.Number
Case 76
MsgBox "Form_Load Error Handler. Form Does Not Exist"
Case Else
AppWideErr (Err.Number)
End Select
End Sub

Private Sub Command1_Click()
On Error GoTo Cmd1Err
Err.Raise 53
Err.Raise 70
Exit Sub

Cmd1Err:
Select Case Err.Number
Case 53
MsgBox "Command 1 Error Handler"
Case Else
AppWideErr (Err.Number)
End Select
Resume Next
End Sub

Private Sub Command2_Click()
Form2.Show
End Sub

Private Sub Command1_Click()
On Error GoTo ThisSubErr
Err.Raise 17
Exit Sub
ThisSubErr:
AppWideErr (Err.Number)
End Sub

Public Sub AppWideErr(lnErrNumber)
Select Case lnErrNumber
Case 70
MsgBox "Generic Routine. Access Denied. See Net Administrator.", , "AppWideErr"
Exit Sub
Case Else
MsgBox "Generic Routine. Unhandled Error: " + Err.Description + " # " & lnErrNumber, , "AppWideErr"
Exit Sub
End Select
End Sub
READ MORE - Cara Membuat Generic Handler Error