Results 1 to 5 of 5

Thread: How Detect Disk In Drive X? [Resolved]

  1. #1

    Thread Starter
    Hyperactive Member Trojan's Avatar
    Join Date
    Dec 2003
    Location
    Area 51
    Posts
    280

    Resolved 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
    MD5How To Detect Disk In Drive X?Time Tickerchanging the owner of a controlSystray HardCore

    • "Programming is like sex: one mistake and you have to support it for the rest of your life."
    • "A program is a spell cast over a computer, turning input into error messages."
    • "WARNING: Keyboard Not Attached. Press F10 to Continue."
    • "Why doesn't DOS ever say 'EXCELLENT command or filename!'"

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  3. #3

    Thread Starter
    Hyperactive Member Trojan's Avatar
    Join Date
    Dec 2003
    Location
    Area 51
    Posts
    280

    Re: How Detect Disk In Drive X?

    can you give me an example?
    MD5How To Detect Disk In Drive X?Time Tickerchanging the owner of a controlSystray HardCore

    • "Programming is like sex: one mistake and you have to support it for the rest of your life."
    • "A program is a spell cast over a computer, turning input into error messages."
    • "WARNING: Keyboard Not Attached. Press F10 to Continue."
    • "Why doesn't DOS ever say 'EXCELLENT command or filename!'"

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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:
    1. Private Sub Command1_Click()
    2.  Dim sSearch As String
    3.  
    4.  On Error GoTo ErrTrap
    5.     'Check to see if files or directorys exist.  If so, then there is some form
    6.     'of disk media in the drive
    7.     sSearch = Dir$("d:\*.*", vbDirectory)
    8.     Exit Sub
    9. ErrTrap:
    10. If Err.Number = 52 Then
    11.   MsgBox "There is no disk media in drive", vbInformation + vbOKOnly
    12. End If
    13. End Sub

    Here is another way:
    VB Code:
    1. Private Sub Command2_Click()
    2. On Error GoTo ErrTrap
    3.     'try to switch to the drive you are checking
    4.     ChDir "E:\"
    5.     Exit Sub
    6. ErrTrap:
    7. If Err.Number = 76 Then
    8.   MsgBox "Drive does not exist", vbInformation + vbOKOnly
    9. End If
    10.  
    11. End Sub
    Last edited by Hack; Jan 7th, 2005 at 07:22 AM.

  5. #5

    Thread Starter
    Hyperactive Member Trojan's Avatar
    Join Date
    Dec 2003
    Location
    Area 51
    Posts
    280

    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
    MD5How To Detect Disk In Drive X?Time Tickerchanging the owner of a controlSystray HardCore

    • "Programming is like sex: one mistake and you have to support it for the rest of your life."
    • "A program is a spell cast over a computer, turning input into error messages."
    • "WARNING: Keyboard Not Attached. Press F10 to Continue."
    • "Why doesn't DOS ever say 'EXCELLENT command or filename!'"

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