|
-
Feb 20th, 2003, 03:44 PM
#1
Thread Starter
Hyperactive Member
Which drive the cd is in?
Hi Everyone
I'm developing a botany program which will include alot of
large( about 300 uncompressed and 300 JPEG) picture files and other media....stuff that would take forever to load as group.
I'd like the program to read the files off the cd, but alas, not
everyone uses E:.
Is there an API function that I can call ( like from Sub Main) to
get the letter of the drive the cd is in? Would I then assign
the return value to a Global?
Some software that my kids use requires the cd in the drive,
that's what I looking for.
Thank you!
-
Feb 20th, 2003, 03:52 PM
#2
Hyperactive Member
-
Feb 20th, 2003, 04:44 PM
#3
Thread Starter
Hyperactive Member
Getting there....
j_jewel
Thanks for the help. I wasn't exactly looking for opening or
closing the drive, but querying where the picture files are.
I can use GETDRIVETYPE, but it returns a value of 5 for both
the DVD and the CD-RW drives.
Is there a function that will return drive letter?
Would I have to get the information
- attempt to open the files
- use an error handler routine to either find them or tell
them to insert the cd?
Questions, Questions! If you can't tell.....I'm a beginner!
-
Feb 20th, 2003, 05:08 PM
#4
-= B u g S l a y e r =-
this sample does what you are onto in your last post.
It scans all cd drives looking for a spec. file (in this case program.txt)
you can do the same, just replace the file with one unique file of your own. 
VB Code:
Option Explicit
Private Declare Function GetLogicalDriveStrings _
Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal _
nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Const DRIVE_CDROM = 5
Private Sub Command1_Click()
Dim tmp As Integer
Dim tmpStr As String
Dim Drives As String
Dim CDsCount As Integer
Dim CDsLetters As String
Dim ret As Long
Dim results As String
'init Drives to 255 spaces
Drives = Space(255)
'get drives, Drives var will look like
'A:\, C:\, D:\, E:\, ..:\
'ret& is the new length of Drives
ret = GetLogicalDriveStrings(Len(Drives), Drives)
For tmp = 1 To ret& Step 4
'get a drive root directory (like "C:\")
tmpStr = Mid(Drives, tmp, 3)
'if drive is a CD
If GetDriveType(tmpStr) = DRIVE_CDROM Then
' CDsCount = CDsCount + 1
CDsLetters = CDsLetters & Left(tmpStr, 1) & " "
End If
Next tmp
'**************my code*****************
Dim sArr() As String
Dim i As Integer
Dim bAllOk As Boolean
sArr = Split(CDsLetters, " ")
For i = 0 To UBound(sArr) - 1 '-1 because of that last space :)
On Error Resume Next
If Dir(sArr(i) & ":\program.txt") <> "" Then
If Err Then
'MsgBox Err.Number & Err.Description
bAllOk = False
Err.Clear
Else
bAllOk = True
End If
Else
bAllOk = False
End If
Next i
If bAllOk Then
MsgBox "The CD is in the drive.Now loading...."
Else
MsgBox "Please insert the CD-ROM."
End If
End Sub
-
Feb 20th, 2003, 06:45 PM
#5
Thread Starter
Hyperactive Member
Fantastic!
Peet
Thank you very much! I'd had gotten the drive #'s and used Mid
to extract the drive letter....Your reply saved me from drowning
in a cumbersome select case thing. We beginners make it soooooo hard.
Set and loaded the pictures right up.....
Thanks Again
RG
-
Feb 21st, 2003, 01:11 AM
#6
-= B u g S l a y e r =-
glad you could use it Rocketdawg
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
|