Syntax
Puts the lines of a BASIC module of the project in place of the directive, every time it appears.
#INSERT "<path>"
#INSERT("<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 directive, then from the project root. / and \ separate folders, .. goes up one. Case is ignored. |
|---|
Good to know
- In the example, the module
snippets/tick.basholds the single linecount = count + 1. It is inserted twice, so it runs twice. - Use it for a piece of code you want repeated. For a file of declarations use
#INCLUDE: a function inserted twice is refused withAmbiguous BASIC overload. #INSERTdoes not count for#INCLUDE: a file inserted earlier is still brought in once by a later#INCLUDE.- Two modules that insert each other are a compile error that names the chain:
Cyclic BASIC include: loop/a.bas -> loop/b.bas -> loop/a.bas. - A path that matches no module is a compile error:
BASIC include file not found: <path>. Errors inside the module are reported with the module's name and its own line number. - One directive per line, in double quotes. After a
:or without the quotes it is not refused, but the program does not start. - It is plain text insertion, done before anything is compiled. Inside a runtime
IFthe lines are always inserted; only their running depends on the condition. - AGK's
#inserthas the same meaning. IncludeFile() is the same directive under PureBasic's name.
Example
snippets/tick.bas
count = count + 1main.bas
count = 0#INSERT "snippets/tick.bas"#INSERT "snippets/tick.bas"Console(Str(count)) ' 2In the manual : The preprocessor