Default File Variable

Default File Variable

Top  Previous  Next

 

For compatibility with other environments, QMBasic supports the concept of the default file variable but, because use of this feature can result in mis-typed programs compiling without errors but not functioning correctly, it must be enabled by use of the STDFIL or STDFIL.SHARED option of the $MODE compiler directive or the equivalent setting in the $BASIC.OPTIONS record.

 

The default file variable allows a program to open a file without referencing a specific variable name.

 

When using the STDFIL.SHARED option of $MODE, the default file variable is an implied reference to the @STDFIL variable. All programs and subroutines executed at the same command processor level share a single default file variable. It is therefore important that an application uses this feature with care. @STDFIL is maintained separately for each command processor level. Thus a program that uses the default file variable can use the QMBasic EXECUTE statement to run a separate program that uses the default file variable to reference a different file. On return from the EXECUTE, @STDFIL references the original file.

 

When using the STDFIL option of $MODE instead of STDFIL.SHARED, the default file variable is maintained separately for each program or subroutine. The @STDFIL variable is local to the program in which it is referenced.

 

A single application can validly include a mix of programs that use both modes but use of both STDFIL and STDFIL.SHARED together in a single program is equivalent to use of STDFIL.

 

 

When this feature is enabled, the syntax of many of the QMBasic statements that access files is modified to allow the file variable to be omitted. The revised syntax for use with the default file variable is as shown below but not referenced elsewhere in this manual.

CLEARFILE {ON ERROR statement(s)}

CLOSE {ON ERROR statement(s)}

DELETE record.id {ON ERROR statement(s)}

DELETEU record.id {ON ERROR statement(s)}

FILELOCK {ON ERROR statement(s)} {LOCKED statement(s)}

FILEUNLOCK {ON ERROR statement(s)}

OPEN {dict.expr, } filename {READONLY} {ON ERROR statement(s)} {THEN statement(s)} {ELSE statement(s)}

OPENPATH pathname {READONLY} {ON ERROR statement(s)} {THEN statement(s)} {ELSE statement(s)}

MATREAD mat FROM record.id {ON ERROR statement(s)} {THEN statement(s)} {ELSE statement(s)}

MATREADL mat FROM record.id {ON ERROR statement(s)} {LOCKED statement(s)} {THEN statement(s)} {ELSE statement(s)}

MATREADU mat FROM record.id {ON ERROR statement(s)} {LOCKED statement(s)} {THEN statement(s)} {ELSE statement(s)}

MATWRITE mat TO record.id {ON ERROR statement(s)}

MATWRITEU mat TO record.id {ON ERROR statement(s)}

READ rec FROM record.id {ON ERROR statement(s)} {THEN statement(s)} {ELSE statement(s)}

READL rec FROM record.id {ON ERROR statement(s)} {LOCKED statement(s)} {THEN statement(s)} {ELSE statement(s)}

READU rec FROM record.id {ON ERROR statement(s)} {LOCKED statement(s)} {THEN statement(s)} {ELSE statement(s)}

RELEASE , record.id {ON ERROR statement(s)}       [Note comma before record.id]

SELECT {TO list} {ON ERROR statement(s)}

SELECTN {TO list} {ON ERROR statement(s)}

SELECTV {TO list} {ON ERROR statement(s)}

WRITE rec TO record.id {ON ERROR statement(s)}

WRITEU rec TO record.id {ON ERROR statement(s)}

 

QM does not support use of the default file variable with READV, WRITEV and the locking related variants of these statements.