Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Curious about Drive List Box

darthmoobeydarthmoobey Member Posts: 140
I wish to make an error check for a Drive List Box, if it searches a drive, but nothing is there, or not located, for it to send a msg box telling the user, and going back to c: drive. right now I ahve this code.

[code]
Private Sub ListDrive_Change()
' Set Directory listing to current drive listing
DirectoryList.Path = listDrive.Drive
End Sub
[/code]

But upon testing it, if I go to A: drive, and have no disk in there, I get a run time error 68, device unavailable. This is obvious why the error was made, but was hoping if anyone had a quick fix code to hopp in there to check if device is available first, then go, if not msgbox and go back to c: drive. I will keep reading up on MSDN but if anyone can help, it would be most appreciated.

the darthmoob

Comments

  • poetfreakpoetfreak Member Posts: 68
    : I wish to make an error check for a Drive List Box, if it searches a drive, but nothing is there, or not located, for it to send a msg box telling the user, and going back to c: drive. right now I ahve this code.
    :
    : [code]
    : Private Sub ListDrive_Change()
    : ' Set Directory listing to current drive listing
    : DirectoryList.Path = listDrive.Drive
    : End Sub
    : [/code]
    :
    : But upon testing it, if I go to A: drive, and have no disk in there, I get a run time error 68, device unavailable. This is obvious why the error was made, but was hoping if anyone had a quick fix code to hopp in there to check if device is available first, then go, if not msgbox and go back to c: drive. I will keep reading up on MSDN but if anyone can help, it would be most appreciated.
    :
    : the darthmoob
    :
    Private Sub Drive1_Change()
    ' Set Directory listing to current drive listing

    On Error GoTo BadDriveFix:
    Dir1.Path = Drive1.Drive
    Exit Sub
    BadDriveFix:
    If Err = 68 Then
    If MsgBox("Drive Not Ready!", _
    vbRetryCancel, "Floppy not inserted" _
    ) = vbRetry Then
    Resume 'try it again now
    Else
    Resume Next 'otherwise exit without change
    End If
    End If
    ' handle unforseen errors ...
    MsgBox "Disk Error " & Err.Description
    Resume Next 'which will also exit without changing :)

    End Sub


  • KDivad LeahcimKDivad Leahcim Member Posts: 3,948
    : I wish to make an error check for a Drive List Box, if it searches a drive, but nothing is there, or not located, for it to send a msg box telling the user, and going back to c: drive. right now I ahve this code.
    :
    : [code]
    : Private Sub ListDrive_Change()
    : ' Set Directory listing to current drive listing
    : DirectoryList.Path = listDrive.Drive
    : End Sub
    : [/code]
    :
    : But upon testing it, if I go to A: drive, and have no disk in there, I get a run time error 68, device unavailable. This is obvious why the error was made, but was hoping if anyone had a quick fix code to hopp in there to check if device is available first, then go, if not msgbox and go back to c: drive. I will keep reading up on MSDN but if anyone can help, it would be most appreciated.
    :
    : the darthmoob
    :

    I do this:

    [code]Private Sub Drive1_Change()

    '"Static" will cause the var to retain it's data
    Static LastDrive As String
    'If "LastDrive" is empty (first run), store current drive
    If LastDrive = "" Then LastDrive = Left$(CurDir$, 1)
    On Error Resume Next
    'Try to change drives in dirlist
    Dir1.Path = Drive1.Drive
    If Err.Number <> 0 Then
    'Got an error, restore last drive (will call this
    'routine again and change dirlist to match)
    Drive1.Drive = LastDrive
    'You can display the error msg here.
    Else
    'No error, store this drive
    LastDrive = Drive1.Drive
    End If

    End Sub
    [/code]

    Good luck!
Sign In or Register to comment.