CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Drive List

  1. #1
    Join Date
    Jun 2000
    Posts
    2

    Drive List

    I am trying to obtain a list of drives for searching for the user to select from for certain documents and I am having a little bit of a problem with the drive scan. The code I am just testing out at this point is failing on a removable drive ex drive A: and errors out of the program. The code is as follows:


    Sub ShowDriveList()
    Dim fs, d, dc, s, n
    set fs = CreateObject("Scripting.FileSystemObject")
    set dc = fs.Drives
    for Each d In dc
    s = s & d.DriveLetter & " - "
    If d.DriveType = Remote then
    n = d.ShareName
    else
    n = d.VolumeName
    End If
    s = s & n & vbCrLf
    next
    MsgBox s
    End Sub




    Right now when run if I have a disk in drive A: it works fine but if I don't have one it doesn't. Is there a way around this?

    Thanks.


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Drive List

    You need to handle the Not ready error yourself using On Error do something
    If you want to ignore the not Ready use

    "On Error Go To somewhere" to bypass the error. I am returning a real simple example of your Sub with a couple of mods

    Sub ShowDriveList()

    Dim fs, d, dc, s, n
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set dc = fs.Drives
    On Error GoTo DriveError
    For Each d In dc
    s = s & d.DriveLetter & " - "
    If d.DriveType = Remote Then
    n = d.ShareName
    Else
    n = d.VolumeName
    End If
    s = s & n & vbCrLf
    Next
    MsgBox s
    Set dc = Nothing
    Set fs = Nothing
    Exit Sub
    DriveError:
    n = "Not Ready"
    Resume Next
    End Sub


    John G

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured