Link to home
Start Free TrialLog in
Avatar of danielmingolla
danielmingolla

asked on

How to detect a mini Device storage (128kb)from inside of mi application?

Hello I have those mini device storages 128kb and I need  to detect automatically from inside of my aplication and import data from it. Right now I use the drivelistbox to detect what letter, but my problem is when somebody don't know what letter is the mini device storage they try to select the others drives list in this combo drivelistbox but giving this as an error which I don't know how to filter that error.
Could somebody tell me how to detect this mini device storage automatically?
Thanks a lot
Daniel
Avatar of mladenovicz
mladenovicz

Try this (need reference to Microsoft Scripting Runtime)

Dim oFSO        As Scripting.FileSystemObject
Dim oDrive      As Scripting.Drive
Dim sType       As String
Dim sMsg        As String
   
    Set oFSO = New Scripting.FileSystemObject
   
    For Each oDrive In oFSO.Drives
        Select Case oDrive.DriveType
            Case 0: sType = "Unknown"
            Case 1: sType = "Removable"
            Case 2: sType = "Fixed"
            Case 3: sType = "Network"
            Case 4: sType = "CD-ROM"
            Case 5: sType = "RAM Disk"
        End Select

       
        sMsg = "Drive " & oDrive.DriveLetter & ": - " & sType
        If oDrive.IsReady Then
            sMsg = sMsg & " - Drive is Ready."
        Else
            sMsg = sMsg & " - Drive is not Ready."
        End If
       
        Debug.Print sMsg

    Next
   
    Set oFSO = Nothing

Drive should be ready, and it's type should be Removable. Also you should check oDrive.TotalSize. HTH
Avatar of danielmingolla

ASKER

Hello and thanks for your answer!!
Your sample looks like if what I need but is not working is not doing nothing I put all your code in a form in the load event and referenced to microsoft scripting but is not doing nothing neither the msgbox appear, could you please let me know what I am doing wrong!!
Thanks again
Daniel
Private Sub Form_Load()
Dim oFSO        As Scripting.FileSystemObject
Dim oDrive      As Scripting.Drive
Dim sType       As String
Dim sMsg        As String
   
    Set oFSO = New Scripting.FileSystemObject
   
    For Each oDrive In oFSO.Drives
       
        If oDrive.IsReady Then
            If oDrive.DriveType = Removable And oDrive.TotalSize = 64274432 Then
                MsgBox oDrive.DriveLetter
            End If
        End If
       
    Next
   
    Set oFSO = Nothing
End Sub

64274432 is size of my USB flash device (64 MB). Replace this with size you need (128 MB = 64274432*2)
ASKER CERTIFIED SOLUTION
Avatar of mladenovicz
mladenovicz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial