Navigation: thinBasic language > Script structure > Pre Parsing directives > #INCLUDE |
|
Description
Instruct the interpreter to read a text file from disk and treat it as an integral part of the source code.
Syntax
#INCLUDE [ONCE] "FileName" [AS COMMENT]
Returns
None
Parameters
Remarks
When the interpreter encounters an #INCLUDE statement, it reads "FileName" from disk and attach the included file inside main script. The result is the same as if the contents of the included file were physically present within the main script. This allows large source files to be broken into smaller "units" that are more manageable.
"FileName" can have a full or relative path. Relative paths are always considered relative to the main script.
If no path is specified, main script path is assumed.
Optional ONCE clause can be specified. If ONCE will be specified, before including "FileName", interpreter will check if "FileName" has already been included. If yes, "FileName" will not be included again.
Including more than once a file can have impredictable results. If the included file contains user functions or variable declarations, a duplicate symbol runtime error will occur.
The following meta variables are supported inside FileName:
Name |
Meaning |
%APP_PATH% |
Insert thinBasic installation path |
%APP_SOURCEPATH% |
Insert current script path |
%APP_INCLUDEPATH% |
Insert thinBasic standard include path |
Meta variables are place holders that will be replaced with relevant values at script run-time.
Optional AS COMMENT clause at the end instructs pre parser to not use include file in parsing process. This directive is mainly used in case you want to add documentation files.
"FileName" can contains ? or * in order to specify a file mask. This option can be useful when:
• | more than one files are to be included |
• | dynamically load files present in a directory (plug-in idea) |
• | other dynamic reasons |
Restrictions
This directive is a pre parsing directive. It means all #INCLUDE statements will be solved before starting script execution.
See also
Examples
Uses "CGI"
Uses "LL"
Uses "ADO"
Uses "FILE"
Dim T0 As Double = TIMER
Dim tmpStr As String
Echo "Content-Type: text/html" & $CRLF & $CRLF
#INCLUDE ONCE "Config.inc"
#INCLUDE ONCE "Includes\DB.inc"
#INCLUDE ONCE "Includes\Theme.inc"
#INCLUDE ONCE "Includes\Header.inc"
#INCLUDE ONCE "Includes\Footer.inc"
'---Initialization routines
Config_Start
SiteDB_Open
Theme_Load
tmpStr = Page_Header
Theme_SetBlock("[Page_Header]", tmpStr)
tmpStr = Page_Footer(T0)
Theme_SetBlock("[Page_Footer]", tmpStr)
Theme_ResolveVars
Theme_Echo
'---CleanUp routines
Config_End
SiteDB_Close
© 2004-2008 thinBasic. All rights reserved. | Version 1.7.0.0 | Web Site: http://www.thinbasic.com |