|
-
Jan 7th, 2005, 06:47 AM
#1
Thread Starter
Hyperactive Member
How Detect Disk In Drive X? [Resolved]
Need a function that returns True or false if a disc is present in any drive..
Thanks in advanced..
Last edited by Trojan; Jan 7th, 2005 at 07:30 AM.
Reason: Resolved
-
Jan 7th, 2005, 06:54 AM
#2
Re: How Detect Disk In Drive X?
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.
-
Jan 7th, 2005, 06:56 AM
#3
Thread Starter
Hyperactive Member
Re: How Detect Disk In Drive X?
can you give me an example?
-
Jan 7th, 2005, 07:19 AM
#4
Re: How Detect Disk In Drive X?
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
Last edited by Hack; Jan 7th, 2005 at 07:22 AM.
-
Jan 7th, 2005, 07:28 AM
#5
Thread Starter
Hyperactive Member
Re: How Detect Disk In Drive X?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|