AKD BASIC User Guide | 3 AKDBASICLanguage
Names for constants follow the same rules as variable names. ‘Forward definitions’ are
allowed. Circular definitions are detected and reported at compile-time. Although it is not
required, it is convenient to adopt a convention of keeping all constants in UPPER_CASE, so
you can easily distinguish between constants and variables in the program.
Constant definitions are entirely ‘folded’ at compile-time. Feel free to write maintainable con-
stant expressions such as:
const LENGTH = 3
const WIDTH = 10
const AREA = LENGTH * WIDTH
The value of AREA is computed at compile-time, so the program does NOT need to compute
this at run-time and the program is easier to maintain if LENGTH changes at some future date.
3.2.6 Alias Definitions
Aliases allow you to define your own names for system resources, such as input / output pins.
The intention is to make it possible for you to use names that are meaningful to you in your par-
ticular application. The format of an alias expression is:
alias <name> = <expression>
For example, the following alias defines application-specific uses of input # 1:
alias CONVEYOR_IS_RUNNING = (DIN1.STATE = 0)
alias CONVEYOR_IS_STOPPED = (DIN1.STATE = 1)
if CONVEYOR_IS_RUNNING then
print“running”
else
print“stopped”
An alias is much more powerful than a constant. Constant expressions are computable at com-
pile-time, while an alias has a value that is only known (in general) at the time it is used. Use ali-
ases with care — too much aliasing can make it very difficult for you to understand the
program.
3.3 Main Program, Subroutines, Functions & Interrupt Handlers
These sections share the same fundamental structure:
<section>
<declarations>
<statements>
<section end>
An example of each of these sections follows, with an explanation of key points.
3.3.1 Main Definitions
For main, a typical definition is:
Main
dim i as integer
i = 1
print i
End Main
23 Kollmorgen™ | March 30, 2012