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
FreeFile
to obtain a file number to use in theFileOpen
procedure.You should call
FreeFile
and store the returned file number to a variable rather than passing theFreeFile
function directly as thefilenumber
argument of theFileOpen
procedure. In this way, you save the file handle for a subsequent call to theFileClose
procedure.After using the
FreeFile
function to retrieve a file handle, you should immediately call theFileOpen
procedure, 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 toFileOpen
fails.
Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.