Is there a way to get the hard drive letter with VB 4.0?
I have an older program written in this language that I am attempting to modify
and need to get the hard drive letter to update it.

Thanks for your help.

major_lost

Not sure in vb4. In vb6 you will be using something similar to -

'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
commented: nice +6

Thank you Andre. The code worked GREAT without any changes. Before I close this thread, can you tell me why it only returns the hard drive versus all of the drive letters? I noticed that 'ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and that the counter cycles through all of the drive letters. I get: "C - Unknown" when I run the code.

Thanks again!!!!!!!!!
major_lost

Only a pleasure. I've tested the code on my side and it returned all the correct descriptions...

C-HD
D-HD
E-CDRom
even my removable disk - I- Removable disc
etc...

I tested on Windows 7 and Vista. Not sure if XP will return the correct values.

Please mark as solved, thanx.

Here is another option using the FileSystemObject

Sub ListDrives()
    Dim fso As Scripting.FileSystemObject 'needs refernce to: Microsoft Scripting Runtime
    Dim fsoDrives As Scripting.drives

    Set fso = New FileSystemObject
    Set fsoDrives = fso.drives
    Dim i As Integer
    Dim letter As String
    Dim driveType As String
    For i = Asc("A") To Asc("Z")
        letter = Chr$(i)
        If fso.DriveExists(letter) Then
            Select Case fso.drives(letter).driveType 'returns DriveTypeConst
                Case Scripting.UnknownType
                    driveType = "Unknown"
                Case Scripting.Removable
                    driveType = "Removable"
                Case Scripting.Fixed
                    driveType = "Fixed"
                Case Scripting.Remote
                    driveType = "Remote"
                Case Scripting.CDRom
                    driveType = "CDRom"
                Case Scripting.RamDisk
                    driveType = "RamDisk"
            End Select
            MsgBox "Drive " & letter & " - " & driveType
        End If
    Next i

    Set fsoDrives = Nothing
    Set fso = Nothing

End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.