Isi module dengan source code dibawah ini:
Option Explicit
Private Type BrowseInfo
lngHwnd As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const MAX_PATH = 260
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem _
As Long)
Private Declare Function lstrcat Lib "Kernel32" Alias "lstrcatA" _
(ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "Shell32" (lpbi _
As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32" _
(ByVal pidList As Long, ByVal lpBuffer As String) As Long
Public Function BrowseForFolder(ByVal strPrompt As String) As _
String
On Error GoTo ehBrowseForFolder
Dim intNull As Integer
Dim lngIDList As Long, lngResult As Long
Dim strPath As String
Dim udtBI As BrowseInfo
With udtBI
.lngHwnd = 0
.lpszTitle = lstrcat(strPrompt, "")
.ulFlags = BIF_RETURNONLYFSDIRS
End With
lngIDList = SHBrowseForFolder(udtBI)
If lngIDList <> 0 Then
strPath = String(MAX_PATH, 0)
lngResult = SHGetPathFromIDList(lngIDList, strPath)
Call CoTaskMemFree(lngIDList)
intNull = InStr(strPath, vbNullChar)
If intNull > 0 Then
strPath = Left(strPath, intNull - 1)
End If
End If
BrowseForFolder = strPath
Exit Function
ehBrowseForFolder:
BrowseForFolder = Empty
End Function
Kemudian pada Properties window ganti nama Module menjadi “mdlDialog”. Lalu aktifkan komponen Common Dialog dengan cara klik Project, lalu pilih Component dan scroll ke bawah lalu cari Microsoft Common Dialog Control 6.0 Centang dan tekan OK.
Setelah itu lihat pada Toolbox, maka akan ada penambahan komponen berupa CommonDialog.
Masukkan 2 buah TextBox, 2 buah CommandButton dan 1 buah CommonDialog. Atur properties pada masing-masing komponen sebagai berikut: (untuk ukuran/ size terserah)
Form
| |
Name
|
frmDialog
|
BorderStyle
|
1 – Fixed Single
|
Caption
|
Menampilkan Dialog Browse
|
TextBox1
| |
Name
|
txtFolder
|
Text
|
Folder
|
TextBox2
| |
Name
|
txtFiles
|
Text
|
Files
|
CommandButton1
| |
Name
|
cmdFolder
|
Caption
|
Browse Folder
|
CommandButton2
| |
Name
|
cmdFiles
|
Caption
|
Browse Files
|
CommonDialog
| |
Name
|
CD1
|
Lalu atur komponen tersebut seperti dibawah ini:
Buka Code Window dan masukkan source code dibawah ini:
Private Sub cmdFiles_Click()
On Error GoTo akhir
Dim Filename As String
CD1.Filter = "Semua File|*.*" 'kamu bisa merubah kode ini sesuai dengan kebutuhan misal Image|*.jpg
CD1.ShowOpen
Filename = CD1.Filename
akhir:
If Len(Filename) > 0 Then
txtFiles.Text = Filename
End If
End Sub
Private Sub cmdFolder_Click()
Dim brwVal As String
brwVal = BrowseForFolder("Select Drive And Directory:")
If Len(brwVal) > 0 Then
txtFolder.Text = brwVal
End If
End Sub
Selesai, coba tekan Run atau F5.
Dapatkan Source Code nya di bawah ini atau masuk pada halaman Download
0 Response to "Membuat Dialog Browse pada Visual Basic 6.0"
Posting Komentar
Yuk stop jadi silent reader, tanpa komentar gan/sis blog ini bukan apa-apa