A Typical flat BASIC Program Layout
Source: Positron8 Compiler User Manual, PDF page 49
The compiler is very flexible, and will allow most types of constants, declarations, and variables to be placed anywhere within the BASIC program. However, it may not produce the correct results, or an unexpected syntax error may occur due to a variable being declared after it is supposed to be used.
The recommended layout for a flat BASIC program is shown below.
Device
'
Declares
'
'
Includes
'
'
Constants and Variables
'
'
Main:
Main Program code goes here
'
'
Subroutines go here
'
For example
Device = 18F26K40
' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600
' Set the Baud Rate for HRsoutLn
'-----------------------------------------
' Load an ADC include file (if required)
Include "ADC.inc"
'-----------------------------------------
' Define Variables
Dim WordVar as Word
' Create a Word size variable
'-----------------------------------------
' Define Constants and/or aliases
Symbol cValue = 10
' Create a constant
'-----------------------------------------
' Main Program Code
'
Main:
WordVar = 10
' Pre-load the variable
GoSub AddIt
' Call the subroutine
HRsoutLn Dec WordVar
' Display the result on the serial terminal
'-----------------------------------------
' Simple Subroutine
AddIt:
WordVar = WordVar + cValue
' Add the constant to the variable
Return
' Return from the subroutine
Of course, it depends on what is within the include file as to where it should be placed within the program, but the above outline will usually suffice. Any include file that requires placing within a certain position within the code should be documented to state this fact.