Close Statement

See Also1SHV5JI              Example1BMZHTS>Low

Concludes input/output (I/O)to a file.

Syntax

Close [[#]filenumber] [,[#]filenumber] . . .

Remarks

The argument filenumber is the number used in the Open statement to open the file.  You can use any numeric expression71RISN 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.


See Also

End StatementLANEND

Open Statement103I7PS

Reset Statement3S7W9S

Stop Statement4K739NO


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."

   MsgBox Msg

   Kill "TEST?"                          ' Remove data files from disk.

End Sub

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.

   Next I

   Close                                 ' Close all files.

End Sub