IncludeFile

Function

Syntax

Puts the lines of a BASIC module of the project in place of the line, every time it appears. It is PureBasic's name for #INSERT.

IncludeFile "<path>"
IncludeFile("<path>")

Parts

<path>The module's name in the project, in double quotes, such as snippets/tick.bas. It is looked up next to the file that holds the line, then from the project root. Case is ignored, of the path and of the word IncludeFile.

Good to know

  • In the example, the module snippets/tick.bas holds the line count = count + 1. Inside the loop it is inserted once and runs three times; the second IncludeFile adds a fourth run.
  • It looks like a command but it is a directive, settled before compiling. It returns nothing and cannot be used in an expression: x = IncludeFile("a.bas") is refused with Unknown BASIC command: IncludeFile().
  • It behaves exactly like #INSERT: no once-only rule, a cycle is a compile error, and an unknown path gives BASIC include file not found: <path>.
  • One per line, alone on it. A trailing ' comment is fine.
  • PureBasic's XIncludeFile (include once) is refused with Not a BASIC statement. Write #INCLUDE.

Example

snippets/tick.bas

count = count + 1

main.bas

count = 0FOR i = 1 TO 3  IncludeFile "snippets/tick.bas"NEXTIncludeFile("snippets/tick.bas")Console(Str(count))   ' 4
In the manual : The preprocessor