$INCLUDE
$INCLUDE is a metacommand that is used to insert a source code file into your program which is then executed at the point of the insertion.
Syntax
Description
- QBasic metacommands must be commented with REM or an apostrophe.
- The sourceFile name must be enclosed in apostrophes and can include a path.
- $INCLUDE is often used to add functions and subs from an external text QBasic code library.
- The $INCLUDE metacommand should be the only statement on a line.
How to $INCLUDE a BAS or Text file with a QB64 Program
- Assemble the code to be reused into a file.
- Declarations (e.g. TYPE, DIM, CONST, SHARED), DATA, SUBs, and FUNCTIONs may all be in the same file which is included at the beginning of a program.
- GOSUB and ERROR handlers can be in the same file with a GOTO to skip execution over them, or they may be in a separate file included at the end of a program.
- By convention, the extension .BI is used for files included at the beginning of a program and .BM for files included at the end of a program. These extensions are not required, any extension can be used as long as the file contains code in plain text (binary files are not accepted).
- Compile the program.
- Note: Once the program is compiled, the included text files are no longer needed with the program EXE.
Availability
-
all
-
all
-
yes
-
yes
-
yes
- Versions before QB64-PE v4.4.0 did not allow interleaving main level code with SUB and FUNCTION definitions, so these definitions had to be at the end of the program (usually in a separate .BM file).
Examples
- Example
- Showcasing a simple program which includes another source file.
'$INCLUDE: 'UTILITIES.BI' 'Use a SUB and constant defined in the included file ShowText ProgramName 'Use a GOSUB handler defined in the included file GOSUB ShowVersion |
'The included file can contain declarations CONST ProgramName = "My Program" CONST Version = "1.3" 'SUB or FUNCTION definitions are allowed SUB ShowText (text$) PRINT text$ END SUB 'GOSUB handlers need to be skipped with a GOTO GOTO utilities_skip_gosubs ShowVersion: PRINT Version RETURN utilities_skip_gosubs: |
More examples
See also