Returns the number of drives
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Function NumberofDrives() As Integer
Dim Buffer As String * 255
Dim BuffLen As Long
Dim DriveCount As Integer
BuffLen = GetLogicalDriveStrings(Len(Buffer), Buffer)
DriveCount = 0
For i = 1 To BuffLen
If Asc(Mid(Buffer, i, 1)) = 0 Then _
DriveCount = DriveCount + 1
Next i
NumberofDrives = DriveCount
End Function
Sub Main()
Debug.Print NumberofDrives
End Sub
Related examples in the same category