Results 1 to 9 of 9

Thread: Driver letter

  1. #1
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Question Unanswered: Driver letter

    With VB, I need to find available driver letters and optionally the drive name.
    Can anyone help me with this?

    Sincerely
    Vestg

  2. #2
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    Letters are not a problem (you can loop A-Z using the DIR() function to test for availablity.

    Names, if I remember correctly, are another issue.

    I think there may be an API call for names. But, if I remember correctly, the names it echo'd were not what I was looking for.

    Remote mounted names appear in the registry, so you can read them there.

    You can use the directory version of the CommonDialogBox as a crude substitution.

  3. #3
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Talking abcdefghijklmnopqrstuvwxyz()

    Thanks for the idea. That will do the job.
    But are there any easier solutions out there?

    best regards
    Vestigo

  4. #4
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Angry Disk with no files on root returns NULL

    Actually, this method ends up with two problems.
    1 - Hitting a CD drive return an error
    2 - Disk with no files on root returns NULL

    Any idea how to overcome problem 2 ?
    Thanks



    Private Sub Disk_Enter()
    Dim I, Alphabet As String, Path As String
    'Alphabet = "ZYXWVUTSRQPONMLKJIHGFEDC" 'NOT OK
    Alphabet = "ZYXWVUTSRQPONMLKJIFEDC" 'OK
    For I = 1 To Len(Alphabet)
    Check_Disk = "" & Mid(Alphabet, I, 1) & ":"
    If Dir(Check_Disk) <> "" Then Path = Mid(Alphabet, I, 1) & ";" & Path
    Next I
    Me.Disk.RowSource = Path
    End Sub

  5. #5
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    Try this:

    Code:
    Function GetListOfValidDriveLetters() As String
    
        Dim i As Byte
        Dim TheseAreGoodDrives As String
    
        TheseAreGoodDrives = ""
        
        For i = 1 To Len("ZYXWVUTSRQPONMLKJIFEDC")
            On Error Resume Next
            ChDrive Mid("ZYXWVUTSRQPONMLKJIFEDC", i, 1)
            Select Case Err
                Case 0:
                    On Error GoTo 0
                    TheseAreGoodDrives = TheseAreGoodDrives + Mid("ZYXWVUTSRQPONMLKJIFEDC", i, 1)
                Case 68:
                    On Error GoTo 0
                Case Else:
                    On Error GoTo 0
                    Stop
            End Select
        Next i
        
        GetListOfValidDriveLetters = TheseAreGoodDrives
        
    End Function
    Ken

    Maverick Software Design

    (847) 864-3600 x2

  6. #6
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    Oh, BTW, since that code I just posted changes the current drive in order to determine if the drive exists, it would be advisible to, at the beginning of that code, use CurDrive() to determine the current drive and then, on the completion of the code, set the drive back to its original setting.
    Ken

    Maverick Software Design

    (847) 864-3600 x2

  7. #7
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Talking

    Lovely, function exact as requested.

    Thanks a lot.

  8. #8
    Join Date
    Nov 2003
    Posts
    1,487
    Here is another flexable alternative:
    Code:
    Public Sub DrivesOnSystem(DrvArray() As String, Optional DrvAvail As Integer, Optional InformIf As Integer)
        'The variable DrvArray() must be passed to this sub-routine and it must be
        'Dimensioned as String in the calling procedure.
    
        'Optional:
        'The received parameter, DrvAvail, (optional) must be either 0 or 1. If 0
        '(default) is passed this function will seek out all drives contained in
        'the computer system. If 1 is passed then this function will seek out only
        'drives that are available and ready to store data.
        
        'Optional:
        'The received parameter, InformIf, (optional) must be either 0 or 1. If 0 (default)
        'is passed this function does nothing other than what is requested by DrvAvail. If
        '1 is passed, this function will seek out all drives contained within the computer
        'system but will also return a colon and backslash along with the drive letter (ie:
        'D:\) if the drive is ready to store data. Drives that are not ready to store data
        'will only have their respective drive letter returned (ie:  D). When InformIf is
        'set to 1, the DrvAvail value is ignored.
    
        Dim i As Integer, x As Integer, a$
        On Error Resume Next
        If InformIf = 1 Then DrvAvail = 0
        Screen.MousePointer = 11
        x = 0: a$ = CurDir
        For i = 65 To 91  'ASCII A to Z)
            ChDir (Chr$(i) & ":\")
            DoEvents
            If Err = 0 Or (DrvAvail = 0 And Err = 75) Then
                 ReDim Preserve DrvArray(x)
                 If InformIf = 1 And Err = 0 Then
                            DrvArray(x) = Chr$(i) & ":\"
                       Else
                            DrvArray(x) = Chr$(i)
                       End If
                x = x + 1: Err = 0
            Else
                Err = 0
            End If
        Next i
        CurDir a$
        Screen.MousePointer = 0
    
        'Always remember to 'Erase' the array (where this function
        'is called from) when you are finished with it so as to free
        'up memory space.
    End Sub
    USAGE:

    Example 1 - Place code into a Command button:
    Code:
        'Check For All Drives In System Whether They Are Ready Or Not.
        Dim x As Integer, DrvArray() As String, Strg As String
        Call DrivesOnSystem(DrvArray())
        For x = 0 To UBound(DrvArray)
            Strg = Strg & "The drive " & DrvArray(x) & _
            " is available on this system." & vbNewLine
        Next x
        MsgBox Strg
        Erase DrvArray
    Example 2 - Place code into a Command button:
    Code:
        'Check For All Drives In System That Are Media Ready Only.
        Dim x As Integer, DrvArray() As String, Strg As String
        Call DrivesOnSystem(DrvArray(), 1)
        For x = 0 To UBound(DrvArray)
            Strg = Strg & "The drive " & DrvArray(x) & _
            " is on this system and is media ready." & vbNewLine
        Next x
        MsgBox Strg
        Erase DrvArray
    Example 3 - Place code into a Command button:
    Code:
        'Check For All Drives In System (That Are Media Ready Only Or Not) and
        'returns the colon and backslash with the drive letter of drive ready to store data.
        'ie:  E:\
        Dim x As Integer, DrvArray() As String, Strg As String
        Call DrivesOnSystem(DrvArray(), 1, 1) 'or Call DrivesOnSystem(DrvArray(),  , 1)
        For x = 0 To UBound(DrvArray)
             If Right$(DrvArray(x), 1) = "\" Then
                Strg = Strg & "The drive " & DrvArray(x) & _
                " is on this system and is media ready." & vbNewLine
                'or use
                'Strg = Strg & "The drive " & Left$(DrvArray(x), 1) & _
                '" is on this system and is media ready." & vbNewLine
             Else
                   Strg = Strg & "The drive " & DrvArray(x) & _
                   " is on this system and is NOT media ready." & vbNewLine
            End If
        Next x
        MsgBox Strg
        Erase DrvArray
    Last edited by CyberLynx; 04-04-04 at 15:20.

  9. #9
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,424
    Provided Answers: 8
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

Posting Permissions

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