Name
FileClose Procedure
Class
Microsoft.VisualBasic.FileSystem
Syntax
FileClose([filenumber][,filenumber][,...])
-
filenumber(optional; Integer) The file number (or numbers) of an open file (or files), opened using the FileOpen procedure
Description
Closes one or more files opened with the FileOpen procedure
Rules at a Glance
If
filenumberis omitted, all open files are closed.If the file you are closing was opened for
OutputorAppend, the remaining data in the I/O buffer is written to the file. The memory buffer is then reclaimed.When the FileClose procedure is executed, the file number used is freed for further use.
filenumbercan either be a literal number, a numeric constant, or a numeric variable.
Programming Tips and Gotchas
With the FileClose procedure, you can close more than one file at once by specifying the file numbers as a comma-delimited list, as shown here:
FileClose(1, 3, 4)
The FileClose procedure does not check first to see if there is a file associated with the given file number. Therefore, no error occurs if you use the FileClose procedure with a nonexistent file number. The drawback to this is that you may inadvertently think you have closed a file, when in fact you haven’t.
VB.NET/VB 6 Differences
FileClose is new to VB.NET. It replaces the
Close statement in VB 6.
See Also
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