Q(uick)BASIC Metacommand: $INCLUDE
Quick View
$INCLUDE
A metacommand that causes QuickBASIC to read in and compile other BASIC source files at specific points during compilation
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- REM $INCLUDE: 'filespec' or ' $INCLUDE: 'filespec'
Description/Parameter(s)
The $INCLUDE metacommand instructs the compiler to temporarily switch from processing one file and instead to read program statements from the BASIC file named in the argument. When the end of the included file is reached, the compiler returns to processing the original file. Because compilation begins with the line immediately following the line in which $INCLUDE occurred, $INCLUDE should be the last statement on a line. The following statement is correct:
- DEFINT I-N ' $INCLUDE: 'COMMON.BAS'
There are two restrictions on using Include files:
- Included files must not contain SUB or GOTO statements
- Included files created with BASICA must be saved with the ,A option.
Example
The ⮜ CALL ABSOLUTE Statement ⮞ programming example uses a $INCLUDE metacommand.
See also:
Syntax
- REM $INCLUDE: 'filespec' or ' $INCLUDE: 'filespec'
Description/Parameter(s)
filespec | The name of a BASIC program file, which can include a path. Use single quotation marks around filespec. |
The $INCLUDE metacommand instructs the compiler to:
- Temporarily switch from processing one file.
- Read program statements from the BASIC file named in filespec.
- Return to processing the original file when the end of the included file is reached.
Because compilation begins with the line immediately following the line in which $INCLUDE occurred, $INCLUDE should be the last statement on the line. For example:
- DEFINT I-N ' $INCLUDE: 'COMMON.BAS'
- When you are running a program from the QBX environment, included files must not contain SUB or FUNCTION statements. When compiling a program from the BC command line, SUB or FUNCTION statements may contain included files.
- Included files created with BASICA must be saved with the ,A option.
- Included files created with QBX must be in text (not binary) format.
Example
This example uses the DateSerial# function to calculate the date value for January 1st in the year of your birth. You are then told what day of the week January 1st fell on in that year. Information is displayed using Year& and Weekday& functions.
Note: To run this example you must use a Quick library that includes the procedures contained in the date/time library files. The following include file must also be present.
'$INCLUDE: 'DATIM.BI'
OPTION BASE 1
DEFINT A-Z
DIM DayOfWeek(7) AS STRING
'Initialize the array.
FOR I = 1 TO 7
READ DayOfWeek$(I)
NEXT I
INPUT "What are the last two digits of your birth year"; Birthyear
'Calculate January 1st of birthyear.
Jan1Date# = DateSerial#(Birthyear, 1, 1)
'Display results.
PRINT "January 1,"; Year&(Jan1Date#); "fell on a ";
PRINT DayOfWeek$(Weekday&(Jan1Date#))
DATA "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"
DATA "Friday", "Saturday", "Sunday"
See also: