Results 1 to 7 of 7

Thread: drive question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86

    Resolved drive question

    i inserted a drive box but it even shows drive's that is not on pc
    and i use a little script like this

    Private Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
    End Sub

    the problem know is when i select a driev that not exist an error shows up
    how can i detect of a driveexist or how can i disable the not existed drivers

    or maybe other possiblity's
    Last edited by davyquyo; Oct 24th, 2004 at 04:23 AM.

  2. #2
    Hyperactive Member toughcoder's Avatar
    Join Date
    Nov 2002
    Location
    Near, Very Near
    Posts
    340
    hello davyquyo,
    there r 2 APIs which u can use. I'm posting the code. Hope this helps

    VB Code:
    1. Private Declare Function GetLogicalDrives Lib "kernel32" () As Long
    2. Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    3.  
    4. Private Sub Form_Paint()
    5.     Dim DriveData As Long, i As Long, strDrives As String
    6.     'get the available drives
    7.     DriveData = GetLogicalDrives
    8.     strDrives = "Available drives:"
    9.     For i = 0 To 25
    10.         If (DriveData And 2 ^ i) <> 0 Then
    11.             strDrives = strDrives + " " + Chr$(65 + i)
    12.         End If
    13.     Next i
    14.     MsgBox strDrives 'display drives
    15.    
    16.         Dim strSave As String
    17.     Me.AutoRedraw = True
    18.     strSave = String(255, Chr$(0))
    19.     ret& = GetLogicalDriveStrings(255, strSave)
    20.     For keer = 1 To 100
    21.         If Left$(strSave, InStr(1, strSave, Chr$(0))) = Chr$(0) Then Exit For
    22.         Me.Print Left$(strSave, InStr(1, strSave, Chr$(0)) - 1) 'print drives
    23.         strSave = Right$(strSave, Len(strSave) - InStr(1, strSave, Chr$(0)))
    24.     Next keer
    25. End Sub
    If Not VB Then Exit
    ------------------------------------------------
    visit me @ http://mzubair.50g.com/

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    ok this is showing the good drives but
    the problem is still there
    when i press e:\
    and there is now cd in it
    the error is still there

    something like this drive is not availaible

  4. #4
    Hyperactive Member toughcoder's Avatar
    Join Date
    Nov 2002
    Location
    Near, Very Near
    Posts
    340
    hello davyquyo,
    why dont u handle that error, i mean when that error comes tell the user to insert a cd into the drive. Use the onError keyword...
    If Not VB Then Exit
    ------------------------------------------------
    visit me @ http://mzubair.50g.com/

  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    VB Code:
    1. Private Sub Drive1_Change()
    2. On Error Goto 1
    3.  
    4.     Dir1.Path = Drive1.Drive
    5.     Exit Sub
    6.  
    7. 1   'Error
    8.     MsgBox "Drive not ready!", vbCritical
    9. End Sub

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    thanx it works

  7. #7
    Hyperactive Member toughcoder's Avatar
    Join Date
    Nov 2002
    Location
    Near, Very Near
    Posts
    340
    anytime davy
    If Not VB Then Exit
    ------------------------------------------------
    visit me @ http://mzubair.50g.com/

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