|
-
Sep 23rd, 2000, 10:44 PM
#1
Thread Starter
Junior Member
How can I exam if there is CD in CDROM
I have examed in this way:
On Error Goto NOCD
...............
Dir "E:\aaa.aaa"
Msgbox "CD In CDROM"
Exit Sub
NOCD:
Msgbox "No CD In CDROM"
Exit Sub
But if the fuction is to long,I don't thibk it can work well.
How can I exam it in a "normal" way? API?
-
Sep 23rd, 2000, 10:59 PM
#2
Try this:
Code:
Function CDInDrive() As Boolean
On Error GoTo ErrHan
Dir "D:\", vbDirectory
DiskInDrive = True
Exit Function
ErrHan:
DiskInDrive = False
End Function
Private Sub Command1_Click()
If CDInDrive() Then
MsgBox "CD detected"
Else
MsgBox "No CD detected"
End If
End Sub
-
Sep 23rd, 2000, 11:07 PM
#3
Origionally by Matt Gates
Code:
Function CDInDrive() As Boolean
On Error GoTo ErrHan
Dir "D:\", vbDirectory
DiskInDrive = True
Exit Function
ErrHan:
DiskInDrive = False
End Function
Private Sub Command1_Click()
If CDInDrive() Then
MsgBox "CD detected"
Else
MsgBox "No CD detected"
End If
End Sub
Not good...
Some people (like me) has D: as a Hard Drive, so it really is a bad idea. Sorry for the correction, but no...
It'll succeed on D: as CD, but as for E: as CD...
-
Sep 24th, 2000, 11:42 AM
#4
Originally posted by jackbee
try this
Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Public Const DRIVE_CDROM = 5
'Get CD Drive ie D, E etc
Function GetCDSource() As String
Dim Srce$
Dim Index%
Dim DriveType As Long
For Index% = Asc("C") To Asc("Z")
DriveType& = GetDriveType(Chr$(Index%) & ":")
If DriveType& = DRIVE_CDROM Then
On Error GoTo NextIndex 'in case CD is empty
If Len(Dir(Chr$(Index%) & ":\",vbDirectory)) > 0 Then
Srce$ = Chr$(Index%)
Exit For
End If
End If
NextIndex:
Next Index%
GetCDSource = Srce$
End Function
There's a much easier way:
Code:
Dim fso As FileSystemObject, d As Object, e As Drives
Set fso = CreateObject("Scripting.FileSystemObject")
Set e = fso.Drives
For Each d In e
If d.DriveType = 4 Then
If d.isready = True Then
MsgBox "CD-Rom " & d.DriveLetter & ": is Ready."
Else
MsgBox "CD-Rom " & d.DriveLetter & ": is Not Ready."
End If
End If
Next
No API , and it gets every CD Drive.
-
Sep 24th, 2000, 01:03 PM
#5
Frenzied Member
A question I always wanted to ask:
do the fso add extra bytes to your project? (DLL needed?)
and can it run on any windows OS? win9*,win2k,winMe,win98se,winNT?
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Sep 24th, 2000, 01:50 PM
#6
Yes, you have to distribute SCRRUN.DLL. It is not necessary to Place it in the setup file because it is included in VBScript 2.0, but you can call the function in HTML and autodownload VBS2.0. REMEMBER, it's a part of VB Script 2.0.
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
|