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

Comments

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of File, Folder and Drive List.

Leave a comment

Sign in or Join us (it's free).

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Related discussion

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...

Want to stay in touch with what's going on? Follow us on twitter!