#INCLUDE

Directive

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.bas declares FUNCTION 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 #INSERT declares 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 #IF branch 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 .bas or .agc file. 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.bas is 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 #include has the same meaning. PureBasic's XIncludeFile is refused: write #INCLUDE.

Example

lib/math.bas

FUNCTION Clamp(value, low, high)  IF value < low THEN EXITFUNCTION low  IF value > high THEN EXITFUNCTION highENDFUNCTION value

main.bas

#INCLUDE "lib/math.bas"#INCLUDE "lib/math.bas"Console(Str(Clamp(15, 0, 10)))   ' 10
In the manual : The preprocessor