#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 "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 six 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 six levels of files (including the primary file).  Note that macros count as #include files for nesting purposes.

See also

WIN32API.INC Updates

Example

' MYHELLO.BAS

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

FUNCTION PBMAIN

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

END FUNCTION