FreeFile Function

See Also266I9S3              ExampleUU1FRX>Low

Returns the next valid unused file number.


FreeFile [( )]


Use FreeFile when you need to supply a file number and you want to ensure that the file number is not already in use.

See Also

Open Statement103I7PS

FreeFile Function Example

The example uses the FreeFile function to return the next available file number.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.


Sub Form_Click ()

   Dim NL, FileNum, Msg                  ' Declare variables.

   NL = Chr(10)                          ' Define newline.

   FileNum = FreeFile                    ' Get unused file number.

   Open "TESTFILE" For Output As FileNum ' Create sample data file.

   Close FileNum                         ' Close file.

   Msg = "The file number returned by the FreeFile function was "

   Msg = Msg & FileNum & "." & NL & NL

   Msg = Msg & "Choose OK to remove the created test file."

   MsgBox Msg                            ' Display results.

   Kill "TESTFILE"                       ' Remove file from disk.

End Sub