#INCLUDE metastatement  

Purpose

Instruct the compiler to read a text file from disk and treat it as an integral part of the source code.

Syntax

#INCLUDE [ONCE] "filespec"

Remarks

Use #INCLUDE to compile the text of another file along with the current file.  filespec is a string constant that follows normal LFN file-naming conventions, and which names a PowerBASIC source code file.  If filespec does not include an extension, the compiler looks for that file name with the default extension of .BAS.

If filespec does not include a path, the compiler scans the search path for each #INCLUDE file before checking the current (default) directory.  For the IDE, the search path can be set in the Compiler  Preferences tab in the Options dialog.  The search path can also be specified when compiling from the command-line by using the /I Include option.

When the compiler encounters an #INCLUDE metastatement, it reads filespec from disk and continues compilation with the source code in filespec.  When the end of filespec is reached, compilation continues with the statement immediately following the #INCLUDE in the original source file.  The result is the same as if the contents of the included file were physically present within the original text.  This allows large source files to be broken into smaller "units" that are more manageable.

#INCLUDE metastatements can be nested as many as twelve levels deep.  That is, an included file can have #INCLUDE metastatements of its own, including files that also have #INCLUDE metastatements, and so on, for a total of twelve levels of files (including the primary file).  Note that macros count as #include files for nesting purposes.

If the optional keyword ONCE is included, the specified file is included only one time during compilation, regardless of how many times it appears in the program.  This is particularly useful when including common declaration files like WIN32API.INC to avoid redundant cod, and the resulting errors.  To be effective, the ONCE option must appear on every #INCLUDE of a particular file.  Effectively, #INCLUDE ONCE means: "Include this file only if it has not already been included."

See also

WIN32API.INC Updates

Example

' MYHELLO.BAS

#INCLUDE ONCE "WIN32API.INC"  'include Windows API calls

FUNCTION PBMAIN

  MessageBox 0, "Hello World!", "PowerBASIC", %MB_OK

END FUNCTION