Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check the A: drive? 3

Status
Not open for further replies.

fingers

Programmer
Nov 17, 2000
17
0
0
How can I check to see if there is a disk in A: or B: drive without causing the head to thrash around by executing a dir$ command. Dir$ tells me what I want to know if there is a disk present but I can't rely on the fact that there will be. I am using VB6.0

Thanks for any help anyone can provide.

Bud
 
Detect If CD/Floppy Disk Is In The Drive

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Add 1 CommandButton (named Command1) and 1 DriveListBox (named Drive1) to your form.
'Choose in the DriveListBox the drive you want to detect, and press the button.
'Insert this code to the module :

Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal _
nVolumeNameSize As Long, lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal _ lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long

'Insert this code to your form:

Private Sub Command1_Click()
erg& = GetVolumeInformation(Drive1.Drive, VolName$, 127&, _
VolNumber&, MCM&, FSF&, FSys$, 127&)
If erg& = 0 Then
MsgBox "There is no media in the drive"
Else
MsgBox "There is a media in the drive"
End If
End Sub

Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX.

Download Demo version on my Site:
Promotions before 02/28/2001 (free source codebook),visite my site
 
Hi "Fingers"

you can handle it in an easier way by using an error handler.

After adding a button of driveListBox you can write the following code:

Private Sub Drive1_Change()
On Error GoTo ErrorHandling

Dim intResult As Integer

ErrorHandling:
If Err.Number = 68 Then 'drive not ready
intResult = MsgBox("Drive not ready. Retry?", vbYesNo, "Error")
If intResult = vbYes Then
Resume
Else
Drive1.Drive = "c:"
End If
Else 'other error occured
MsgBox "General Error"
Drive1.Drive = "c:"
End If
End Sub

Let your "Fingers" do it...

Naftali.
 
You are going to get the "thrashing" no matter what you do. You can't check a drive without actually checking it.

Both of the above are roughly equivalent to: [tt]

Public Function DriveReady(Drive$) As Boolean
On Error GoTo NotReady
A$ = Dir(Drive$ & "\*.*")
DriveReady = True
Exit Function
NotReady:
DriveReady = False
End Function


If DriveReady("A:") Then
MsgBox "Disk is in drive A:"
Else
MsgBox "No disk in A:"
EndIf
[/tt]

VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top