Name
FreeFile Function
Class
Microsoft.VisualBasic.FileSystem
Syntax
FreeFile( )
Return Value
An integer representing the next available file number
Description
Returns the next available file number for use in a
FileOpen function
Programming Tips and Gotchas
It is good programming practice to always use
FreeFileto obtain a file number to use in theFileOpenprocedure.You should call
FreeFileand store the returned file number to a variable rather than passing theFreeFilefunction directly as thefilenumberargument of theFileOpenprocedure. In this way, you save the file handle for a subsequent call to theFileCloseprocedure.After using the
FreeFilefunction to retrieve a file handle, you should immediately call theFileOpenprocedure, particularly if your file access code resides in a multithreaded application or component. Failure to do so may cause the same handle to be assigned to two different variables, so that one of the calls toFileOpenfails.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access