|
-
Sep 21st, 2000, 11:39 PM
#1
Seemingly simple. I have a form with 10 Command buttons, they all are used to Browse for a dir path. Each button returns the choosen dir to it's associated text box. So this is what I want, rather than copy the code for each button(10) I'd like to call a Public Function from each button, therfore only writing the code once.
Here is my problem. How/What variable do I pass to the function, and how do I get it to return to the proper textbox? Have I confused you? Here is my Code for the Browse Button:
Option Explicit
Private Type BrowseInfo
pIDLRoot As Long
pszDisplayName As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Const BIF_RETURNONLYFSDIRS = 1
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 Browse()
On Error GoTo Err_Browse
Dim lpIDList As Long
Dim udtBI As BrowseInfo
Dim iNull As Integer
Dim sPath As String
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
'Get the path from the IDList
SHGetPathFromIDList lpIDList, sPath
'free the block of memory
CoTaskMemFree lpIDList
iNull = InStr(sPath, vbNullChar)
If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
End If
Me.txtDir1 = sPath 'This is where I need the help
Exit_Browse:
Exit Sub
Err_Browse:
MsgBox Err.Description
Resume Exit_Browse
End Sub
Here I would call the Function
Private Sub Browse1_Click()
Browse
End Sub
The Browse Buttons a labled Browse1-10
The Text Boxes are labled txtDir1-10
The code is marked with this caption where I belive I need the help
'This is where I need the help
I know I need to pass variables but how?
TIA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|