ClassMicrosoft.VisualBasic.FileSystem SyntaxDim result As Integer = FreeFile( ) DescriptionThe FreeFile function returns the next available file number for use with the FileOpen procedure. Usage at a Glance
ExampleThis 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 DifferencesIn Visual Basic 2005, the My.Computer.FileSystem object provides more robust access to file management features. See AlsoFileOpen Procedure |