Need a function that returns True or false if a disc is present in any drive..
Thanks in advanced..
Printable View
Need a function that returns True or false if a disc is present in any drive..
Thanks in advanced..
If you try to switch to a drive that does not contain a useable, formatted disk, I believe the error that is return is 52 (test this to be sure). Trap for whatever error is returned, and take whatever action is necessary.
can you give me an example?
I was right, it is error 52 that is returned if no disk media is found. In this example, I use drive D: which is my CD drive (I don't have a floppy drive a: on my machine.)VB Code:
Private Sub Command1_Click() Dim sSearch As String On Error GoTo ErrTrap 'Check to see if files or directorys exist. If so, then there is some form 'of disk media in the drive sSearch = Dir$("d:\*.*", vbDirectory) Exit Sub ErrTrap: If Err.Number = 52 Then MsgBox "There is no disk media in drive", vbInformation + vbOKOnly End If End Sub
Here is another way:VB Code:
Private Sub Command2_Click() On Error GoTo ErrTrap 'try to switch to the drive you are checking ChDir "E:\" Exit Sub ErrTrap: If Err.Number = 76 Then MsgBox "Drive does not exist", vbInformation + vbOKOnly End If End Sub
Thanks Hack!
Here is what I wanted:
Public Function DiscInDrive(xDirve as string) As Boolean
Dim sSearch As String
On Error GoTo ErrTrap
sSearch = Dir$(xDirve & ":\*.*", vbDirectory)
DiscInDrive = True
ErrTrap:
If Err.Number = 52 Then
DiscInDrive = False
End If
End Function