Difference between revisions of "$INCLUDE"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
m (Fix link)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''$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.
+
[[$INCLUDE]] is a metacommand that is used to insert a source code file into your program which is then executed at the point of the insertion.
  
  
''Syntax:'' {[[REM]] | [[REM|']] } $INCLUDE: 'sourcefile'
+
{{PageSyntax}}
 +
: {[[REM]] | [[apostrophe|']] } [[$INCLUDE]]: '{{Parameter|sourceFile}}'
  
  
* There must always be a [[REM]] or [[REM|']] comment before the $INCLUDE metacommand.
+
{{PageDescription}}
* The source file MUST have REM or apostrophies around the name.
+
* QBasic [[Metacommand|metacommands]] must be commented with [[REM]] or an apostrophe.
* The source file included can contain any BASIC statement except [[GOTO]]
+
* The {{Parameter|sourceFile}} name must be enclosed in apostrophes and can include a path.
* QB 4.5 can use [[DECLARE]] SUB in BI files such as [[QB.BI]].  
+
* $INCLUDE is often used to add functions and subs from an external text QBasic code library.
* '''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.
* 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.
 
  
  
<center>'''How to $INCLUDE a BAS or Text file with a QB64 Program'''</center>
+
===How to $INCLUDE a BAS or Text file with a QB64 Program===
 +
* Assemble the code to be reused into a file.
 +
* Common extensions are '''.BI''' (for declarations, usually included in the beginning of a program) or '''.BM''' (with SUBs and FUNCTIONs, usually included at the end of a program).
 +
** Any extension can be used, as long as the file contains code in plain text (binary files are not accepted).
 +
* $INCLUDE any [[DIM]], [[CONST]], [[SHARED]] arrays or [[DATA]] at the '''beginning''' of the main program code.
 +
* $INCLUDE [[SUB]]s or [[FUNCTION]]s at the bottom of the main program code '''after any SUB procedures.'''
 +
** '''Note:''' [[TYPE]] definitions, [[DATA]] and [[DECLARE LIBRARY]] can be placed inside of sub-procedures.
 +
* '''Compile''' the program.
 +
*''Note: Once the program is compiled, the included text files are no longer needed with the program EXE.''
  
:* 1) Assemble your 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!''' Save the text files to use them like '''Library files'''.
 
  
 +
{{PageExamples}}
 +
{{CodeStart}}''' '$INCLUDE:''' 'QB.BI'{{CodeEnd}}
  
''Example:'' ''' '$INCLUDE:''' '[[QB.BI]]'
 
  
 +
===More examples===
 +
* [[SelectScreen]] (member-contributed $INCLUDE demo)
 +
* [[FILELIST$]] (member-contributed file search function)
 +
* [[SAVEIMAGE]] (SUB program that creates bitmaps)
  
  
 
+
{{PageSeeAlso}}
''See Library Examples:''
 
 
 
[[SelectScreen]] (member $INCLUDE demo)
 
 
 
[[FILELIST$ (function)]] (member FILE Search function)
 
 
 
[[SAVEIMAGE]] (SUB program that creates bitmaps)
 
 
 
 
 
''See also:''
 
 
 
 
* [[INTERRUPT]], [[INTERRUPTX]]  
 
* [[INTERRUPT]], [[INTERRUPTX]]  
 
 
* [[TYPE]], [[DIM]]
 
* [[TYPE]], [[DIM]]
 
 
* [[Metacommand]]
 
* [[Metacommand]]
 
  
  
 
{{PageNavigation}}
 
{{PageNavigation}}

Latest revision as of 15:36, 17 February 2021

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


Syntax

{REM | ' } $INCLUDE: sourceFile


Description

  • QBasic metacommands must be commented with REM or an apostrophe.
  • The sourceFile name must be enclosed in apostrophes and can include a path.
  • $INCLUDE is often used to add functions and subs from an external text QBasic code library.
  • The $INCLUDE metacommand should be the only statement on a line.


How to $INCLUDE a BAS or Text file with a QB64 Program

  • Assemble the code to be reused into a file.
  • Common extensions are .BI (for declarations, usually included in the beginning of a program) or .BM (with SUBs and FUNCTIONs, usually included at the end of a program).
    • Any extension can be used, as long as the file contains code in plain text (binary files are not accepted).
  • $INCLUDE any DIM, CONST, SHARED arrays or DATA at the beginning of the main program code.
  • $INCLUDE SUBs or FUNCTIONs at the bottom of the main program code after any SUB procedures.
  • Compile the program.
  • Note: Once the program is compiled, the included text files are no longer needed with the program EXE.


Examples

'$INCLUDE: 'QB.BI'


More examples


See also



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