File Variable

A file variable is the symbolic way to access a file after being previously opened in a BASIC program. File variables are assigned with the open statement.

Syntax

open filename to file.var...

read var from file.var...

write var on file.var...

Description

A file variable contains the assigned file pointers and are used by subsequent BASIC file input and output statements.

Once explicitly assigned, using these statements references the given file by its file variable.

clearfile

delete

matread

matreadu

matwrite

matwriteu

open

read

readu

readv

readvu

release

select

write

writev

writevu

Unlike numeric and string variables, a file variable cannot be output with a print or crt statement, used in a string or arithmetic expression, or displayed in the FlashBASIC or BASIC debugger. A file variable can be assigned to other variables in a standard assignment statement or copied to other variables, in the form:

file.var.b = file.var.a

 

WARNING

For Windows: Copying file variables can be dangerous since a subsequent close on any of the file variables will close the file. Thus, any remaining file variables (containing a copy of the now invalid file handle) may be incorrectly allocated to the wrong file.

Example(s)

This opens the invoices file to a file variable called inv.f. Throughout the rest of the program, inv.f is used for any reference to the invoices file.

open "invoices" to inv.f else...

An item is read from the inv.f (the file variable opened in the first example).

readu item from inv.f,"cust.345" else...