Syntax
Puts the lines of a BASIC module of the project in place of the directive, once per program. Later requests for the same module are skipped.
#INCLUDE "<path>"
#INCLUDE("<path>")Parts
| <path> | The module's name in the project, in double quotes, such as lib/math.bas. It is looked up next to the file that holds the directive, then from the project root. / and \ separate folders, .. goes up one. Case is ignored. |
|---|
Good to know
- In the example, the module
lib/math.basdeclaresFUNCTION Clamp(value, low, high). It is asked for twice and included once. - Use it for files of declarations: functions,
TYPEs,GLOBALs. Inserting such a file twice with#INSERTdeclares everything twice, which is refused. - The skip works across files: a module already included by another module is not included again.
- A path that matches no module is a compile error on the directive's line:
BASIC include file not found: <path>. A file inside a dropped#IFbranch is never read and may be missing. - The compiler never reads a disk path or a URL. A module is created with File, New Script, BASIC Module, or imported from a
.basor.agcfile. Its name is its path. - One directive per line, alone on it; a trailing
'comment is fine. After a:it is not refused, but it stays as text and the program does not start. - Without the double quotes,
#INCLUDE lib/math.basis not refused either: it compiles, and the program does not start. - It is plain text insertion, done before anything is compiled. Inside a runtime
IF, the file is inserted whatever the condition. To leave a file out, wrap the directive in#IF. - Two modules that include each other stop silently: the second request is skipped.
- AGK's
#includehas the same meaning. PureBasic'sXIncludeFileis refused: write#INCLUDE.
Example
lib/math.bas
FUNCTION Clamp(value, low, high) IF value < low THEN EXITFUNCTION low IF value > high THEN EXITFUNCTION highENDFUNCTION valuemain.bas
#INCLUDE "lib/math.bas"#INCLUDE "lib/math.bas"Console(Str(Clamp(15, 0, 10))) ' 10In the manual : The preprocessor