Kyle
05-06-03, 02:34 PM
Hey all, just got my first copy of Visual Basic 6. Completely new to it and I've been following alot of tutorials and stuff. Anyway, I have this script to open a file browsing dialog without an OCX.
Declarations:
--------------------------------------------------
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Code:
-----------------------------------------------------------
Private Sub imgbrowser_Click()
'Place the following code in under a command button or in a menu, etc...
Dim ofn As OPENFILENAME
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Form1.hWnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
ofn.lpstrFile = Space$(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space$(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = CurDir
ofn.lpstrTitle = "Open File..."
ofn.flags = 0
Dim a
a = GetOpenFileName(ofn)
If (a) Then
MsgBox (Trim$(ofn.lpstrFile))
Else
End If
End Sub
Want to know how I could change this to open and report a Directory instead of a single File like it is now. Thanks a bunch all!
Kyler1
P.S. Will probably have many questions here in the future as I learn this.:D
Declarations:
--------------------------------------------------
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Code:
-----------------------------------------------------------
Private Sub imgbrowser_Click()
'Place the following code in under a command button or in a menu, etc...
Dim ofn As OPENFILENAME
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Form1.hWnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
ofn.lpstrFile = Space$(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space$(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = CurDir
ofn.lpstrTitle = "Open File..."
ofn.flags = 0
Dim a
a = GetOpenFileName(ofn)
If (a) Then
MsgBox (Trim$(ofn.lpstrFile))
Else
End If
End Sub
Want to know how I could change this to open and report a Directory instead of a single File like it is now. Thanks a bunch all!
Kyler1
P.S. Will probably have many questions here in the future as I learn this.:D