O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 filenumber is omitted, all open files are closed.

  • If the file you are closing was opened for Output or Append, 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.

  • filenumber can 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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required