A Typical Procedural BASIC Program Layout
Positron8 · Revision 4.0.6.5 · PDF page 48
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 or declare being created after it is supposed to be used.
The recommended layout for a program containing procedures is shown below.
Device ' Always required
'
Xtal declare ' Always required
'
'
General declares
'
'
Includes
'
'
Constants and/or Variables
'
'
Main:
Main Program code goes here
'
'
Procedures 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
'-----------------------------------------
' Load an include file (if required)
'
Include "MyInclude.inc"
'-----------------------------------------
' Create Variables
'
Dim MyWord as Word ' Create a Word size variable
'-----------------------------------------
' Define Constants and/or aliases
'
Symbol MyConst = 10 ' Create a constant
'-----------------------------------------
' Main Program Code
'
Main:
MyWord = 10 ' Pre-load the variable
MyWord = AddIt(MyWord, MyConst) ' Call the procedure
HRsoutLn Dec MyWord ' Display the result on the serial terminal
'-----------------------------------------
' Simple Procedure
'
Proc AddIt(pMyWord1 as Word, pMyWord2 as Word), Word
Result = pMyWord1 + pMyWord2 ' Add the two variables as the result
EndProc
