Results 1 to 6 of 6

Thread: Which drive the cd is in?

  1. #1

    Thread Starter
    Hyperactive Member Rocketdawg's Avatar
    Join Date
    Feb 2003
    Location
    Back in the doghouse
    Posts
    294

    Question 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!

  2. #2
    Hyperactive Member
    Join Date
    May 2002
    Location
    Omaha, NE
    Posts
    263

    This might help you...


  3. #3

    Thread Starter
    Hyperactive Member Rocketdawg's Avatar
    Join Date
    Feb 2003
    Location
    Back in the doghouse
    Posts
    294

    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!

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    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:
    1. Option Explicit
    2. Private Declare Function GetLogicalDriveStrings _
    3. Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal _
    4. nBufferLength As Long, ByVal lpBuffer As String) As Long
    5.  
    6. Private Declare Function GetDriveType Lib "kernel32" _
    7. Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    8.  
    9. Private Const DRIVE_CDROM = 5
    10.  
    11. Private Sub Command1_Click()
    12. Dim tmp As Integer
    13. Dim tmpStr As String
    14. Dim Drives As String
    15. Dim CDsCount As Integer
    16. Dim CDsLetters As String
    17. Dim ret As Long
    18. Dim results As String
    19. 'init Drives to 255 spaces
    20. Drives = Space(255)
    21. 'get drives, Drives var will look like
    22. 'A:\, C:\, D:\, E:\, ..:\
    23. 'ret& is the new length of Drives
    24. ret = GetLogicalDriveStrings(Len(Drives), Drives)
    25.  
    26. For tmp = 1 To ret& Step 4
    27. 'get a drive root directory (like "C:\")
    28. tmpStr = Mid(Drives, tmp, 3)
    29. 'if drive is a CD
    30. If GetDriveType(tmpStr) = DRIVE_CDROM Then
    31. ' CDsCount = CDsCount + 1
    32. CDsLetters = CDsLetters & Left(tmpStr, 1) & " "
    33. End If
    34. Next tmp
    35.  
    36. '**************my code*****************
    37.  
    38. Dim sArr() As String
    39. Dim i As Integer
    40. Dim bAllOk As Boolean
    41. sArr = Split(CDsLetters, " ")
    42. For i = 0 To UBound(sArr) - 1 '-1 because of that last space :)
    43.     On Error Resume Next
    44.     If Dir(sArr(i) & ":\program.txt") <> "" Then
    45.         If Err Then
    46.             'MsgBox Err.Number & Err.Description
    47.             bAllOk = False
    48.             Err.Clear
    49.         Else
    50.             bAllOk = True
    51.         End If
    52.     Else
    53.         bAllOk = False
    54.     End If
    55. Next i
    56. If bAllOk Then
    57.     MsgBox "The CD is in the drive.Now loading...."
    58. Else
    59.     MsgBox "Please insert the CD-ROM."
    60. End If
    61. End Sub
    -= a peet post =-

  5. #5

    Thread Starter
    Hyperactive Member Rocketdawg's Avatar
    Join Date
    Feb 2003
    Location
    Back in the doghouse
    Posts
    294

    Talking 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

  6. #6
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    glad you could use it Rocketdawg
    -= a peet post =-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width