$INCLUDEONCE: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
No edit summary |
||
Line 31: | Line 31: | ||
:* First save the include files in your qb64pe folder, then take the main program. | :* First save the include files in your qb64pe folder, then take the main program. | ||
{{Text|Save as "incl.bm"}} | {{Text|'''Save as "incl.bm"'''|black}} | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Text|<nowiki>'included 2 times by test.bas</nowiki>|#919191}} | {{Text|<nowiki>'included 2 times by test.bas</nowiki>|#919191}} | ||
Line 41: | Line 41: | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{Text|Save as "once.bm"}} | {{Text|'''Save as "once.bm"'''|black}} | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Text|<nowiki>'included by test.bas and incl.bm</nowiki>|#919191}} | {{Text|<nowiki>'included by test.bas and incl.bm</nowiki>|#919191}} | ||
Line 51: | Line 51: | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{Text|Save as "test.bas"}} | {{Text|'''Save as "test.bas"'''|black}} | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Text|<nowiki>'this is a test for $INCLUDEONCE behavior</nowiki>|#919191}} | {{Text|<nowiki>'this is a test for $INCLUDEONCE behavior</nowiki>|#919191}} |
Revision as of 14:55, 8 February 2024
The $INCLUDEONCE metacommand, when placed in include files, prevents that the file's contents is injected multiple times into a program, even if the file is included multiple times directly or indirectly through other include files.
Syntax
Description
- Aa QB64 metacommand it does not require a comment ' or REM before it.
- It can be placed everywhere in an include file, but must be the only thing in the line, hence whithout additional whitespace or comments.
- Even if placed in the middle or the end of the file, it always designates the entire file contents.
- If placed in the main program, $INCLUDEONCE does nothing and is simply ignored without error.
- $INCLUDEONCE will not work if placed inside pre-compiler $IF..$ELSE...$END IF blocks.
Availability
Availability
- Example
- Show how the command prevents included code to be injected multiple times.
- First save the include files in your qb64pe folder, then take the main program.
Save as "incl.bm"
'included 2 times by test.bas PRINT PRINT "This prints from file incl.bm, it should appear 2 times on screen." '$INCLUDE: 'once.bm' |
Save as "once.bm"
'included by test.bas and incl.bm $INCLUDEONCE PRINT PRINT "This prints from file once.bm, and should appear only once on screen." |
Save as "test.bas"
'this is a test for $INCLUDEONCE behavior PRINT "This prints from the test.bas main program." '$INCLUDE: 'incl.bm' '$INCLUDE: 'once.bm' '$INCLUDE: 'incl.bm' END |
See also