Project 06/2005
Danaher
Motion
52 Rev
E
M-SS-005-03l
3. 3
P
ROGRAM
D
ECLARATIONS
You must declare the start of programs and subroutines. For programs, use
the Program…End Program keywords. Use Sub…End Sub keywords for
subroutines.
The Program…End Program keywords mark the boundary between the
variable declaration section and the main program. Each task must have only
one Program keyword and end with the End Program keyword.
Program ‘Standard form of program command
<
code for program>
End Program
The AutoExec task, which must be loaded and run automatically at power-up
must have
CONTINUE
following Program.
You pass parameters (either scalar or array) to the subroutine, which can
then be used in the code of the subroutine. In the declaration line for the
subroutine (SUB
<name>
), you declare the variable names and types of the
parameters to pass. Parameters are passed either by reference or by value
(ByVal). The default method is to pass parameters by reference. Arrays are
passed only by reference. When you pass a variable (whether the variable is
local to the task or is global) by reference, you pass the address of the
variable to the subroutine, which changes the value of the variable (if the
code of the subroutine is written to do this). When you pass a variable by
value (ByVal) a copy of the value of the local variable is passed to the
subroutine. The subroutine cannot change the value of the local variable.
The syntax for defining a subroutine is:
SUB <
name
> ({{ByVal} <
p_1
> as <
type_1
> }…{, {ByVal} <
p_n
> as
type_n
>})
{
local variable declaration
}
{
subroutine code
}
END SUB
There is no explicit limit on the number of subroutines allowed in a task. All
subroutines must be located following the main program, and must be contained
wholly outside the main program. Subroutines can only be called from within the
task where they reside. Subroutines may be recursive (call itself).