Article ID: 141020
Article Last Modified on 12/9/2003
#If Win32 Then
Private Declare Function GetDriveType Lib "kernel32" Alias
"GetDriveTypeA" (ByVal nDrive As String) As Long
#Else
Private Declare Function GetDriveType Lib "kernel" (ByVal nDrive As
Integer) As Integer
#End If
Function Freedrive()
Dim DriveNum As Integer, FirstFreeDrive As String
Dim FirstDrive As Integer
DriveNum = -1
Do
DriveNum = DriveNum + 1 ' start at drive zero.
#If Win32 Then
NextDrive$ = Chr$(DriveNum + 65) + ":\"
FirstDrive% = GetDriveType(NextDrive$)
#Else
FirstDrive% = GetDriveType(DriveNum)
#End If
' GetDriveType returns zero if it cannot determine drive
' type or returns 1 if the specified drive does not exist.
#If Win32 Then
Loop Until FirstDrive% = 1
#Else
Loop Until FirstDrive% = 0
#End If
' DriveNum of 0 means Drive A, 1=B, 2=C, 3=D, 4=E, 5=F, and so on:
FirstFreeDrive = Chr$(DriveNum + 65) + ":"
Freedrive = FirstFreeDrive
End Function
Private Sub Form_Click ()
Cls
Print "The next available (unused) drive letter is: "; Freedrive()
' More handy tips: The "App" object below is found in VB 2.0
' and 3.0 (but not 1.0).
Print "The title for the EXE in Windows Task Manager: "; app.Title
Print "The name of this EXE, or project in VB, is: "; app.EXEName
Print "The path to this application is: "; app.Path
End Sub
Additional query words: 2.00 3.00 4.00 vb4win vb4all
Keywords: kbnetwork kbcode KB141020