Difference between revisions of "$INCLUDE"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 9: Line 9:
 
* The source file included can contain any BASIC statement except [[GOTO]]  
 
* The source file included can contain any BASIC statement except [[GOTO]]  
 
* QB 4.5 can use [[DECLARE]] SUB in BI files such as [[QB.BI]].  
 
* QB 4.5 can use [[DECLARE]] SUB in BI files such as [[QB.BI]].  
* '''QB64 users can use all statements in their include files.''' The $INCLUDE of a SUB or a  Function should be after your main program! Otherwise you will get the '''QB64''' compiler error "Statement cannot be placed between SUB/FUNCTIONs"
+
* '''QB64 users can use all statements in their include files.''' The $INCLUDE of a SUB or a  Function should be after ALL of your program code including SUBs and Functions! Otherwise you will get the '''QB64''' compiler error "Statement cannot be placed between SUB/FUNCTIONs"
 
* The $INCLUDE metacommand should be the only statement on a line since execution progresses ''after'' the line of the metacommand.
 
* The $INCLUDE metacommand should be the only statement on a line since execution progresses ''after'' the line of the metacommand.
 
* $INCLUDE is often used to [[DECLARE]] functions and subs used in an external library.
 
* $INCLUDE is often used to [[DECLARE]] functions and subs used in an external library.
  
 +
 +
<center>'''How to include a BAS or Text file with a Program'''</center>
 +
 +
:* 1) Assemble you text code into a TEXT file and name it something with a .BI or .BM file name extension. '''NOT as .TXT!'''
 +
:* 2) [[$INCLUDE]] any [[DEFINT]], [[DIM]], [[TYPE]], [[SHARED]] arrays or [[DATA]] at the very beginning of the main program code.
 +
:* 3) $INCLUDE [[SUB]]s or [[FUNCTION]]s at the very bottom of the main program code AFTER any SUB procedures.
 +
:* 4) '''Compile''' the program with the included text files in the '''QB64''' folder!
  
  
Line 24: Line 31:
 
[[SelectScreen]] (member $INCLUDE demo)  
 
[[SelectScreen]] (member $INCLUDE demo)  
  
[[_FILE$ (function)]] (member FILES function)
+
[[_FILE$ (function)]] (member FILE Search function)
 +
 
 +
[[SAVEIMAGE]] (SUB program that creates bitmaps)
  
  
 
''See also:''  
 
''See also:''  
  
[[INTERRUPT]]  
+
* [[INTERRUPT]], [[INTERRUPTX]]  
  
[[INTERRUPTX]]  
+
* [[TYPE]], [[DIM]]
  
[[Metacommand]]
+
* [[Metacommand]]
  
  
  
 
{{PageNavigation}}
 
{{PageNavigation}}

Revision as of 22:08, 18 November 2010

$INCLUDE is a metacommand that is used to insert a source file into your program which is then executed at the point of the insertion.


Syntax: {REM | ' } $INCLUDE: 'sourcefile'


  • There must always be a REM or ' comment before the $INCLUDE metacommand.
  • The source file MUST have REM or apostrophies around the name.
  • The source file included can contain any BASIC statement except GOTO
  • QB 4.5 can use DECLARE SUB in BI files such as QB.BI.
  • QB64 users can use all statements in their include files. The $INCLUDE of a SUB or a Function should be after ALL of your program code including SUBs and Functions! Otherwise you will get the QB64 compiler error "Statement cannot be placed between SUB/FUNCTIONs"
  • The $INCLUDE metacommand should be the only statement on a line since execution progresses after the line of the metacommand.
  • $INCLUDE is often used to DECLARE functions and subs used in an external library.


How to include a BAS or Text file with a Program
  • 1) Assemble you text code into a TEXT file and name it something with a .BI or .BM file name extension. NOT as .TXT!
  • 2) $INCLUDE any DEFINT, DIM, TYPE, SHARED arrays or DATA at the very beginning of the main program code.
  • 3) $INCLUDE SUBs or FUNCTIONs at the very bottom of the main program code AFTER any SUB procedures.
  • 4) Compile the program with the included text files in the QB64 folder!


Example: ' $INCLUDE: 'QB.BI'



See Library Examples:

SelectScreen (member $INCLUDE demo)

_FILE$ (function) (member FILE Search function)

SAVEIMAGE (SUB program that creates bitmaps)


See also:




Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page