Library code snippets
File, Folder and Drive List
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
Related articles
Related discussion
-
Run-time error '91'
by converter2009 (1 replies)
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
This thread is for discussions of File, Folder and Drive List.