Solved

any GetDir function?

Posted on 2001-06-18
6
578 Views
Last Modified: 2012-06-27
Hi, are there any function in VB6 like GetDir() that will display a select directory messagebox and let user to choose a directory and then return the path?

0
Comment
Question by:chuyan
  • 4
  • 2
6 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 6201586
0
 
LVL 33

Accepted Solution

by:
hongjun earned 50 total points
ID: 6201602
Try this. You need to have a command button named "Command1". Place the code in form code window.

Option Explicit

Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const MAX_PATH = 260

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

Private Declare Function lstrcat Lib "kernel32" _
Alias "lstrcatA" (ByVal lpString1 As String, ByVal _
lpString2 As String) As Long

Private Type BrowseInfo
   hWndOwner 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 Sub Command1_Click()
'Opens a Browse Folders Dialog Box that displays the
'directories in your computer
Dim lpIDList As Long 'Declare Varibles
Dim sBuffer As String
Dim szTitle As String
Dim tBrowseInfo As BrowseInfo

szTitle = "Hello World. Click on a directory and " & _
"it's path will be displayed in a message box"
'Text to appear in the the gray area under the title bar
'telling you what to do

With tBrowseInfo
   .hWndOwner = Me.hWnd 'Owner Form
   .lpszTitle = lstrcat(szTitle, "")
   .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
End With

lpIDList = SHBrowseForFolder(tBrowseInfo)

If (lpIDList) Then
   sBuffer = Space(MAX_PATH)
   SHGetPathFromIDList lpIDList, sBuffer
   sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
   MsgBox sBuffer
End If

End Sub

hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6201607
Note of the following EE policy.

50 pts = Easy Question
100 pts = Moderate Question
200 pts = Hard Question

hongjun
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:nutwiss
ID: 6201612
hongjun... I assume all you did was copy & paste a sample you already had?

0
 
LVL 33

Expert Comment

by:hongjun
ID: 6201631
Ya. I got it from a web last time.

hongjun
0
 
LVL 4

Expert Comment

by:nutwiss
ID: 6201643
stop whingeing about points then :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Computer crashes, following error message in event manager 5 133
MsgBox 2 47
VB6 - Compare and highlight cell not the same 3 42
Passing a Text Box name to a Sub 6 69
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now