User Guide
Using Subroutines
91
A
xcess Programming Language
DEFINE_CALL 'DO SWITCH' (CARD,INPUT,OUTPUT)
{
SEND_STRING CARD,"'CI',ITOA(INPUT),'O',ITOA(OUTPUT),'T'"
}
This subroutine is defined as having 3 parameters, CARD, INPUT and OUTPUT (enclosed in
parentheses), which are essentially local variables of the subroutine. These variables, however, have
their initial values set by the parameters in the CALL statement which called the routine. Here is a
CALL to this subroutine:
DEFINE_PROGRAM
PUSH[TP,49] (* SWITCHER 1 *)
CALL 'DO SWITCH' (SWT,3,7)
This calls the subroutine 'DO SWITCH' and assigns the value SWT to CARD, 3 to INPUT, and 7 to
OUTPUT. The 'DO SWITCH' subroutine uses a string expression to construct the string 'CI3ØTT'
and then sends the string to the card named SWT. The same subroutine can be used with different
parameters to produce different strings. Here are some examples:
DEFINE_PROGRAM
PUSH[TP,5Ø] (* SWITCHER 2 *)
CALL 'DO SWITCH' (SWT,1,2)
PUSH[TP,51] (* SWITCHER 3 *)
CALL 'DO SWITCH' (SWT,2,12)
PUSH[TP,52] (* SWITCHER 4 *)
CALL 'DO SWITCH' (SWT,1Ø,2Ø)
Passing values back to the caller
A parameter variable can be modified inside a subroutine, like any other type of variable. After the
code in the subroutine has been executed, and before Axcess returns to the caller, Axcess attempts
to copy the values in the parameter variables back into the caller's parameters. This is only
successful if the subroutine is called with variables in the CALL statement. For example:
DEFINE_CALL 'SQUARE' (NUMBER)
{
NUMBER = NUMBER * NUMBER
}
DEFINE_PROGRAM
PUSH[TP,65]
{
X = 5
CALL 'SQUARE' (X)
SEND_STRING Ø,"'X NO EQUALS 25',$ØD,$ØA"
}
PUSH[TP,66]
{
X = 25
CALL 'SQUARE' (X)
SEND_STRING Ø,"'X NO EQUALS 625',$ØD,$ØA"
}