See Also Example
Concludes input/output (I/O)to a file.
Close [[#]filenumber] [,[#]filenumber] . . .
The argument filenumber is the number used in the Open statement to open the file. You can use any numeric expression as long as it evaluates to the number of an open file.
A Close statement with no arguments closes all open files..
The association of a file with filenumber ends when a Close statement is executed. You then can reopen the file using the same or a different file number, or you can reuse the file number to open a different file.
Using a Close statement for a file that was opened for Output or Append writes the final buffer of output to the operating system buffer for that file. Close releases all Visual Basic buffer space associated with the closed file.
The Close statement complements the Open statement.
Close Statement Example
The example uses Close to close all three files opened for Output. 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 Msg ' Declare variable.
Make3Files ' Create data files.
Msg = "Several test files have been created on your disk. "
Msg = Msg & "Choose OK to remove the test files."
Kill "TEST?" ' Remove data files from disk.
Sub Make3Files ()
Dim I, FNum, FName ' Declare variables.
For I = 1 To 3
FNum = FreeFile ' Determine next file number.
FName = "TEST" & FNum
Open FName For Output As FNum ' Open file.
Print #I, "This is a test." ' Write string to file.
Close ' Close all files.