Results 1 to 6 of 6

Thread: find the drive in the computer ? - for experts

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    92
    hi !

    i want to know how i can defin to combo box to show me the list of all the drive that the user have in his computer .

    E.g : if i have in my computer the drive : a,b,c,d,e i will see in the combobox a list with all the drive type .

    10x .

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Why don't you use a DriveListBox?

  3. #3
    Guest
    Try this. Make a Form with a ComboBox and a CommandButton and insert the following code into the Form.

    Code:
    Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    
    Private Sub Command1_Click()
    
        Dim Dtype As Integer
        Dim CurLetter As String
        Dim DriveType As Long
        
        'Cycle through the ASCII codes for A-Z
        For Dtype = 65 To 89
        
            'Convert the ASCII code to a letter
            CurLetter = Chr(Dtype)
            'The the :\ suffix to the Drive
            CurLetter = CurLetter & ":\"
            'Get the Drive type
            DriveType = GetDriveType(CurLetter)
            'If Drive exsists, then add it to the Combobox
            If DriveType <> 1 Then Combo1.AddItem (CurLetter)
            
        Next Dtype
    
    End Sub

  4. #4
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    You could also put this in the form load:

    Code:
    Private Sub Form_Load()
    Dim fso, sDrives, d
    
    Set fso = CreateObject("scripting.filesystemObject")
    
    Set sDrives = fso.Drives
      For Each d In sDrives
        List1.AddItem d.DriveLetter & ":\"
      Next
        
    End Sub

  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    That's easy.. get a list of all drives available by checking each letter:

    Code:
    'Module
    Public Const Drive_Unknown = 0
    Public Const Drive_NoRootDir = 1
    Public Const Drive_Removable = 2
    Public Const Drive_Fixed = 3
    Public Const Drive_Remote = 4
    Public Const Drive_CDRom = 5
    Public Const Drive_RamDisk = 6
    
    Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    
    'Code
    Dim A As Long
    Dim ABC As String
    Dim Temp As Long
    Dim Desc As String
    
    ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    
    Combo1.Clear
    For A = 1 To Len(ABC)
        Temp = GetDriveType(Mid(ABC, A, 1) & ":\")
        
        Desc = ""
        Select Case Temp
        Case Drive_Unknown
            Desc = "Unknown"
        Case Drive_NoRootDir
            'Desc = "No root directory"
        Case Drive_CDRom
            Desc = "CDRom"
        Case Drive_Fixed
            Desc = "HD"
        Case Drive_RamDisk
            Desc = "Ram drive"
        Case Drive_Remote
            Desc = "Remote"
        Case Drive_Removable
            Desc = "Removable disc"
        End Select
        
        If Not Desc Like "" Then: Combo1.AddItem Mid(ABC, A, 1) & " - " & Desc
    Next

  6. #6
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Hm, we all post at nearly the same time

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