Results 1 to 4 of 4

Thread: Drive List Box

  1. #1

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334
    Why do I get an error when I try this?

    Code:
    Private Sub Drive1_Change()
        Dim sDrive$
        
        Dir1.Path = Drive1.Drive ' error occurs here.
          sDrive = Drive1.Drive
        
        Label6.Caption = fn_EvalDriveType(sDrive) 
    
    End Sub
    
    Function fn_EvalDriveType(sDrive As String) As String
        
        Dim lD_Type as Variant, 
        lD_Type = GetDriveType(sDrive & Chr(0))
                 
    End Function
    The error occurs when you select a network drive eg 'g: [\\MA000013\F]'.

    Also, why does the MSDN in VS6 say that the GetDriveType call returns a string eg 'DRIVE_UNKNOWN'when the declare is a long? :Confused:
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    What error are you actually getting?
    Mark
    -------------------

  3. #3
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386
    GetDriveType returns a long, you can declare constants with these values (like DRIVE_UNKNOWN), not sure if they're in the api textviewer (can't check right now...)

  4. #4

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334
    Mark, the error was something systemy - I solved it by forcing it to carry on on errors.

    Crazy,

    How? I've put the constants in, but how do I force it to link the long 5 to the constant DRIVE_CDROM? I want to put it into a string.

    such as

    label6.caption= <Drive_Type> has x freespace from a total of y.


    Here's what I do at the moment . . .

    Code:
    Function fn_EvalDriveType(sDrive As String) As String
        On Error Resume Next
        
        Dim lD_Type As Long, lFree As Currency, ltotal As Long, sType$, sID$, lClusSize As Long, lByteSize As Long, lFreeClus As Long, lTotClus As Long
            lD_Type = GetDriveType(sDrive & "\" & Chr(0))
            
            Select Case lD_Type
                Case 1
                    sType = "Drive_Unknown"
                Case 2
                    sType = "Drive_Removable"
                Case 3
                    sType = "Drive_Fixed"
                Case 4
                    sType = "Drive_Remote"
                Case 5
                    sType = "Drive_CDROM"
                Case 6
                    sType = "Drive_RAMDisk"
                Case Else
                    sType = "Error - Invalid Drive/Dir"
            End Select
          
          GetDiskFreeSpace Left(sDrive, 2) & "\" & Chr(0), lClusSize, lByteSize, lFreeClus, lTotClus
          
          lFree = ((lByteSize * lClusSize) / 1024) * ((lFreeClus) / 1024)
          ltotal = ((lByteSize * lClusSize) / 1024) * ((lTotClus) / 1024)
          
          sID = "Mb"
          
          Select Case ltotal
            Case Is > 1024
                ltotal = ltotal / 1024
                lFree = lFree / 1024
                sID = "Gb"
          End Select
          barDisk.Max = ltotal
          barDisk.Value = lFree
          
     
          fn_EvalDriveType = sType & vbCrLf & (lFree) & sID & " of " & (ltotal) & sID
          
    End Function
    Bearing in mind that this only me playing with API and not serious code!!!




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