CLOSE

CLOSE

Top  Previous  Next

 

The CLOSE statement closes a file previously opened using the OPEN or OPENPATH statement.

 

 

Format

 

CLOSE file.var {ON ERROR statement(s)}

 

where

 

file.varis a file variable for an open file.

 

The file associated with the given file variable will be closed and file.var converted to integer zero. Any other file variable which refers to the same file, either from a separate OPEN or from copying the file variable, will be unaffected.

 

The ON ERROR clause is provided for source program compatibility with other systems and will never be executed by QMBasic programs.

 

Files do not always need to be closed explicitly. Local variables are released when a program or subroutine returns and files associated with local file variables are closed automatically. File variables in common areas will not be affected.

 

Closing a file inside a transaction destroys the file variable but defers the actual close until the transaction ends. Rolling back the transaction will not reinstate the file variable.

 

 

Example

 

OPEN "STOCK.FILE" TO STOCK ELSE ABORT "Cannot open file"

...further statements...

CLOSE STOCK

 

This program fragment opens a file, processes it and then closes the file.