FILE

FILE


FIELD Index Level file.variable
Syntax FILE file1 {, file2 ...}  
Category BASIC
Type Statement
Description compiler directive to use attribute definition items in the file's dictionary while compiling the program.

Multiple files can be specified with the same statement, separated by commas. File paths are currently not allowed in the "file" statement.

The "file" statement is typically used to allow the use of attribute definition items to identify the attribute count ("ac") of the field and automatically apply dictionary correlative codes to the field value in the item.

When the FlashBASIC compiler encounters a "file" statement, it opens the dictionary of the file specified by "file1", creates the executable code to open the data portion of the file during execution, scans the FlashBASIC code for references to the given file and dimensions an array with the same name as the file specified.

The size of the dimensioned array is determined by the compiler. It scans through the program looking for references to attribute names as dimensioned array subscripts (e.g. file1(credit.limit)). After it has found all references to the given file, it takes the "highest" attribute count reference derived, adds 1 to it, and uses the resulting value as the size of the dimensioned array.

After an item is read from the file, attributes within the item may be referenced by using the attribute name from the associated dictionary as the array subscript. Correlative processing codes found in the file dictionary are executed, but output-conversions are not. Values within an attribute can be specified by appending a command and a value count to the attribute name or number.

"read" and "write" statements can not specify the file.variable when the array name "file1" is used as the variable.

The file pointer is assigned to the file.variable in the form "fv.file1" and references the data section of the file opened.
Options
See Also OPEN READNEXT READ statements & functions file.reference processing codes MATREAD default file variables
Example file entity
id = "100"
read entity from id then
if entity(name) = "" then crt "no name!"
end

The file "entity" is bound by the "file" statement.  When item "100" is successfully read, the "name" field is checked. If the name field is null, "no name" is output to the terminal.

fv.entity = access(1)
if not(assigned(fv.entity)) then file entity

This determines if the file.variable "fv.entity" has been assigned by Access of the Update processor. If it has not been assigned, the "file" statement is executed. This technique is particularly useful when calling subroutines from Access, and prevents having to reopen a file each time the routine is called. Using this logic, the "file" statement is executed once.
Warnings D3 does not currently support the use of "pathnames" in the "file" statement. This prevents opening an alternate data section on a file. The way around this limitation is to build a q-pointer to the appropriate data section and use the q-pointer in the "file" statement.

When referencing numeric attribute numbers (e.g. entity(1)), if there are adi's in the dictionary with numeric item-id's (e.g. "1"), the adi will be used and not the "direct" (numeric) reference. The sequence of precedence is adi first, followed by numeric reference; therefore, care must be used when mixing numeric and alphanumeric references.

Changes to attribute definition items made after the program has been compiled will not be reflected in the object code. Since "binding" takes place during the compile phase, the program must be recompiled whenever an attribute count or correlative is changed.

Since the file command creates an array for each file opened, filenames must follow array naming conventions. So all numeric filenames are not supported.
Compatibility
FIELD Index Level file.variable