PDA

View Full Version : VB Noobie...


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

parse27
05-07-03, 07:18 AM
ordinarily, if you want to do what you want to do using an ocx, you'd be using a directory list box to return a string containing the directory you want your program to report.

bottomline is i think you should call the library where the directory list box resides instead of calling the library of a common dialog.

just my opinion. :)

Kyle
05-07-03, 11:55 AM
OK, well actually i found that this works very nicely and i found that if i set the output to:

Before:
MsgBox (Trim$(ofn.lpstrFile))

After:
MsgBox (Trim$(CurDir))

Then DUHHH it displays the directory selected! :) Such simple little things to.

Another Simple question I have is that the controls within my form are not scaleable, such as when the form is maximized there is all this extra space, normally windows will move, and resize there components when maximizing/minimizing. How do i set this??

Thanks alot,
Kyler1