Top  Previous  Next


The FILE statement provides a way to reference data in files using field names defined in the dictionary.


This statement is provided for compatibility with other systems and its use is discouraged.





FILE name, ...




nameis a comma separated list of files to be processed



The FILE statement opens the named files for processing in the current program. The QMBasic compiler will process the associated dictionary to allow use of field names as described below. Note that any change to the dictionary may require the program to be recompiled.


Note that the FILE statement has no error handling clause. If the file cannot be opened, any subsequent access to it will fail.


After a file has been opened using the FILE statement, a record can be read using a modified form of the READ statement:

READ name FROM id

where name is the file name in the FILE statement and id is the key of the record to be read. This form of the READ statement take the same optional clauses as a normal READ. The locking variants (READL and READU) are also supported.


After a record has been read, data from that record can be accessed using a construct:


where name is the file name and field is a field name defined in the dictionary. Note that QMBasic restricts this construct such that field must be a D-type item or an A or S-type item with no correlative. Calculated values are not supported.


Records may be written to the file using a modified form of the WRITE (or WRITEU) statement:

WRITE name TO id

where name is the file name in the FILE statement and id is the key of the record to be written.


Apart from the above special cases, use of name in a file handling statement or function refers to the file variable associated with the file. Use of name in any other context refers to the dynamic array that will be used implicitly by READ or WRITE statements.


Use of the FILE statement is not recommended in new developments as it requires that the file is opened separately in every program that will access it rather than using a file variable in a common block for best performance. The syntax of the associated statements is also likely to be confusing as the same name references either the file variable or the data depending on its context.










This program fragment opens the ORDERS file, reads the record for a given order number and displays the customer number from this record.