How to view/select Folder like CommonDialog in VB6.0

I would like to view or select folder like “CommonDialog”- Box ( That was for only for file) in VB 6.0 .
  “DirListBox” does not meet my user requirements,  They want to select Folder as the way they select file using “CommonDialog”- in vb 6.0.
can you help me on that…?
Plz Help me on that…
Thanks in Advance
muntasirrahmanAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Sadly, I am aware of no way to set an initial directory.  There are actually two dialogs, an "old style" and a "new style".  The newer dialog is more robust, allowing the user to created directories, drag and drop, etc...

It can be accessed by using the BIF_USENEWUI new flag:

    Private Const BIF_USENEWUI = &H40

    With bi
        .hOwner = 0
        .lpszTitle = szDialogTitle
        .ulFlags = BIF_RETURNONLYFSDIRS Or BIF_USENEWUI
    End With

The rest of the code remains the same.

For more info take a look here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shbrowseforfolder.asp

Idle_Mind
0
 
JR2003Commented:
I've had this same issue. YOu can show a directory selection list but I've never found a way of initialising this to the desired path.

I have my own form I have written with the following controls:
Buttons - cmdCancel and cmdOk
DriveListBox - Drive1
DirectoryListBox - Dir1


Option Explicit

Private sPath As String
Private sDrive As String
Public bCancel As Boolean

Private Sub cmdCancel_Click()

    sPath = ""
    Unload Me

End Sub

Private Sub cmdOk_Click()
   
    sPath = Dir1.Path
    bCancel = False
    Unload Me

End Sub


Private Sub Drive1_Change()

    On Error GoTo Trap
    Dir1.Path = Drive1.Drive
    GoTo SkipTrap
   
Trap:

If vbRetry = MsgBox("Error " & Err.Number & vbNewLine & Err.Description, vbRetryCancel Or vbCritical) Then
    Resume
Else
    Dir1.Path = ""
End If

SkipTrap:

End Sub


Public Property Get Path() As String
   
    Path = sPath
   
End Property


Public Property Let Path(Path As String)
   
    On Error Resume Next
    sPath = Path
    sDrive = Left$(sPath, 2)
    Drive1.Drive = sDrive
    With Dir1
        .Path = Drive1.Drive
        .Path = sPath
    End With
   
End Property


Private Sub Form_Load()
   
    bCancel = True
   
End Sub



The code to use the form is this

    Dim sPath As String
   
    Dim f As frmLocateDir
    Set f = New frmLocateDir
    With f
       .Path = "C:\" 'Initialise to whatever you want
       .Show vbModal
        If Not .bCancel Then
          sPath = .Path
        End If
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
In a Module:
Option Explicit

Private Type BROWSEINFO
  hOwner As Long
  pidlRoot As Long
  pszDisplayName As String
  lpszTitle As String
  ulFlags As Long
  lpfn As Long
  lParam As Long
  iImage As Long
End Type

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
            "SHGetPathFromIDListA" (ByVal pidl As Long, _
            ByVal pszPath As String) As Long
           
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
            "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
            As Long
           
Private Const BIF_RETURNONLYFSDIRS = &H1

Public Function BrowseFolder(szDialogTitle As String) As String
  Dim x As Long, bi As BROWSEINFO, dwIList As Long
  Dim szPath As String, wPos As Integer
 
    With bi
        .hOwner = 0
        .lpszTitle = szDialogTitle
        .ulFlags = BIF_RETURNONLYFSDIRS
    End With
   
    dwIList = SHBrowseForFolder(bi)
    szPath = Space$(512)
    x = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
   
    If x Then
        wPos = InStr(szPath, Chr(0))
        BrowseFolder = Left$(szPath, wPos - 1)
    Else
        BrowseFolder = ""
    End If
End Function


Using it from a Form:
Private Sub Command1_Click()
    Dim fileName As String
    fileName = BrowseFolder("Select a folder")
    If fileName <> "" Then
        MsgBox fileName
    End If
End Sub
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
JR2003Commented:
Idle_Mind,
Is there anyway you can initialise the browse so it starts of in a user specified directory and not always at "My Computer" level?
JR
0
 
muntasirrahmanAuthor Commented:
Hi
    It meets my requirements.
Thanks a  lot …
It would be better if I could select a folder by default(ie: \\Gpra740\d\msc) while run my program rater than My Document. is that possible ?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
See my previous post.

Regards,

{pseudocode} / {Time} ± ¼*ƒ(Me.Thoughts÷3)^² = Idle »(°_°)« Mind


0
 
JR2003Commented:
I know it's a bit late but this is definitely worth a look. It allows you to set the initial directory and use the standard folder dialog.

http://www.mvps.org/btmtz/browsdlg/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.