Microsoft KB Archive/100834: Difference between revisions
From BetaArchive Wiki
(importing KB archive) |
m (Text replacement - """ to """) |
||
Line 63: | Line 63: | ||
<li><p>Add the following code to the General Declarations section of Form1:</p> | <li><p>Add the following code to the General Declarations section of Form1:</p> | ||
<pre class="codesample"> ' Enter the following Declare statement as one, single line: | <pre class="codesample"> ' Enter the following Declare statement as one, single line: | ||
Declare Function GetDriveType Lib | Declare Function GetDriveType Lib "kernel" | ||
(ByVal nDrive As Integer) As Integer | (ByVal nDrive As Integer) As Integer | ||
Line 77: | Line 77: | ||
Loop Until FirstDrive% = 0 | Loop Until FirstDrive% = 0 | ||
' DriveNum of 0 means Drive A, 1=B, 2=C, 3=D, 4=E, 5=F, and so on: | ' DriveNum of 0 means Drive A, 1=B, 2=C, 3=D, 4=E, 5=F, and so on: | ||
FirstFreeDrive = Chr$(DriveNum + 65) + | FirstFreeDrive = Chr$(DriveNum + 65) + ":" | ||
Freedrive = FirstFreeDrive | Freedrive = FirstFreeDrive | ||
End Function | End Function | ||
Line 85: | Line 85: | ||
Cls | Cls | ||
Print | Print "The next available (unused) drive letter is: "; Freedrive() | ||
' More handy tips: The | ' More handy tips: The "App" object below is found in VB 2.0 | ||
' and 3.0 (but not 1.0). | ' and 3.0 (but not 1.0). | ||
Print | Print "The title for the EXE in Windows Task Manager: "; app.Title | ||
Print | Print "The name of this EXE, or project in VB, is: "; app.EXEName | ||
Print | Print "The path to this application is: "; app.Path | ||
End Sub | End Sub |
Latest revision as of 09:21, 20 July 2020
Article ID: 100834
Article Last Modified on 12/9/2003
APPLIES TO
- Microsoft Visual Basic 2.0 Standard Edition
- Microsoft Visual Basic 3.0 Professional Edition
- Microsoft Visual Basic 2.0 Professional Edition
- Microsoft Visual Basic 3.0 Professional Edition
This article was previously published under Q100834
SUMMARY
The Visual Basic program in this article shows by example how to find the next available (unused) drive letter in Windows. This could be useful when making network connections to a new drive letter.
MORE INFORMATION
Step-by-Step Example
The Freedrive function defined below returns the next drive letter available in Windows, followed by a colon (:).
- Start Visual Basic. Form1 is created by default.
Add the following code to the General Declarations section of Form1:
' Enter the following Declare statement as one, single line: Declare Function GetDriveType Lib "kernel" (ByVal nDrive As Integer) As Integer Function Freedrive () Dim DriveNum As Integer, FirstFreeDrive As String Dim FirstDrive As Integer DriveNum = -1 Do DriveNum = DriveNum + 1 ' start at drive zero. FirstDrive% = GetDriveType(DriveNum) ' GetDriveType returns zero if it cannot determine drive ' type or returns 1 if the specified drive does not exist. Loop Until FirstDrive% = 0 ' 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
In the Form_click event, add the following statements:
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
- Run the program, and click the form.
Additional query words: 2.00 3.00
Keywords: kbnetwork kbcode KB100834