Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
Class
Microsoft.VisualBasic.FileSystem Syntax
Dim result As Integer = FreeFile( )
Description
The FreeFile function returns the next available file number for use with the FileOpen procedure. Usage at a Glance
Example
This example shows that file numbers should be used immediately. The following code is correct. Dim fileNum1 As Integer Dim fileNum2 As Integer fileNum1 = FreeFile( ) FileOpen(fileNum1, "c:\file1.txt", OpenMode.Input) fileNum2 = FreeFile( ) FileOpen(fileNum2, "c:\file2.txt", OpenMode.Input)
The following code, however, is incorrect, since fileNum1 and fileNum2 will likely be assigned the same file number. Dim fileNum1 As Integer Dim fileNum2 As Integer fileNum1 = FreeFile( ) fileNum2 = FreeFile( ) FileOpen(fileNum1, "c:\file1.txt", OpenMode.Input) ' ----- The next line will generate an error. FileOpen(fileNum2, "c:\file2.txt", OpenMode.Input)
Version Differences
In Visual Basic 2005, the My.Computer.FileSystem object provides more robust access to file management features. See Also
FileOpen Procedure |
Категории