Default File Variables

The statements below make use of a feature known as default file variables:

clearfile

delete

matread

matreadu

matwrite

matwriteu

open

read

readu

readv

readvu

release

select

write

writev

writevu

Note: Most experts agree that use of this feature should be avoided as it makes program maintenance more difficult, but here is a discussion of how they work.

When a file is opened with an open statement, it is usually assigned to a file variable for referencing the file later in the program with any of the above statements. This takes the general form:

open "customers" to customer.file else...

The operative word here is to. In this case it assigns the actual location (represented internally as a base, modulo and separation) to the customer file variable. Later in the program, when an item is read from the file, the file variable displays in the appropriate form of a read statement, as in the form:

read customer.item from customer.file else...

Here, the operative word is from. With default file variables, nothing is explicitly assigned during the open statement, as in the form:

open "customers" else...

Therefore, any subsequent attempt to read from or write to the file does not require the file variable reference, as illustrated in the form:

read customer.item else...

There can be only one default file variable in a BASIC program. Any subsequent file needed for input or output must have an explicitly assigned file variable during the open statement, or it takes the place of the default file.