This example shows you how to integrate the three file system controls: FileListBox, DirListBox and DriveListBox to create a browse for file dialog box
Simply add a FileListBox, called lstFiles, a DirListBox called lstFolders and a DriveListBox called lstDrives. Finally, add the code below to the form.
'
Dim mfMustExist As Integer
Dim mfCancelExit As Integer
Dim LastDrive As String
Private Sub lstFolders_Change()
Static intBusy As Integer
On Error Resume Next
If intBusy = False Then
intBusy = True
' Change the current directory
ChDir lstFolders.Path
If Err = 0 Then
' If an error
does not occur, then
' update file
and directory list
lstFiles.Path =
lstFolders.Path
lstDrives.Drive = Left$(lstFolders.Path, 2)
Else
' If an error
occurs - cancel it
Err = 0
End If
intBusy = False
End If
End Sub
Private Sub lstDrives_Change()
Dim Ans As String
On Error Resume Next
Start:
lstFiles.Path = lstFolders.Path
lstFolders.Path = lstDrives.Drive
' If and error occurs
Select Case Err
Case 68
' Err = not
accessable
Ans =
MsgBox(lstDrives.Drive & " is not accessible", vbRetryCancel +
vbCritical)
If Ans =
vbRetry Then
Err = 0
GoTo Start
Else
' Error reading drive, switch
' to last one
lstDrives.Drive = LastDrive
End If
Case 0
Exit Sub
Case Else
' Unexpected
error
MsgBox
"Unexpected Error " & Err & " : " & Error
lstDrives.Drive = LastDrive
End Select
End Sub
Private Sub Form_Load()
' set file list path
lstFiles.Path = lstFolders.Path
' set last drive
LastDrive = lstDrives.Drive
End Sub
Comments