
Using Subroutines
92
Axcess Programming Language
When the subroutine SQUARE is called with a variable as a parameter (in this case, X), a series of
events occurs.
!
The value of the variable (in this case, 5) is assigned to NUMBER.
!
The subroutine takes the parameter, multiplies it by itself (squaring it) and assigns the
result back to itself.
!
Axcess then reassigns NUMBER back to the variable X, so that upon return from the
subroutine, X will contain its previous value squared.
However, if a constant value is passed to the routine, a reassignment cannot be made. For example:
CALL 'SQUARE' (5)
This will assign the value 5 to the parameter variable NUMBER in the subroutine, and NUMBER
will be squared. However, Axcess cannot take the value in NUMBER and reassign it to the constant
value 5. A routine in which a parameter is expected to return a result should not be called with a
constant value as that parameter. To use a constant value as a parameter to this subroutine, and still
get a new value returned, rewrite the DEFINE_CALL to have two parameters, as shown below:
DEFINE_CALL 'SQUARE' (NUMBER,RESULT)
{
RESULT = NUMBER * NUMBER
}
Here are some examples of using this subroutine:
CALL 'SQUARE' (5,X)(* on return, X will contain 25 *)
CALL 'SQUARE' (X,Y)(* on return, X will contain 25, Y will contain 625 *)
It is important to note that the reassignment of the parameter variable to the caller's variable
happens after the subroutine is finished and before any other code is executed. This could lead to a
hard-to-find bug:
DEFINE_VARIABLE
GLOBAL
DEFINE_CALL 'BUGGY' (PARAM)
{
PARAM = 1Ø
GLOBAL = 2Ø
}
DEFINE_PROGRAM
GLOBAL = 5
CALL 'BUGGY' (GLOBAL)
(* What will GLOBAL contain here? *)
In this example, GLOBAL contains the value 1Ø at the comment statement. In the subroutine
BUGGY, after GLOBAL is set to 2Ø, Axcess reassigns the value in PARAM to the variable in the
CALL statement which called BUGGY-in this case, GLOBAL. The parameter variable PARAM
contains the value 1Ø at the end of the subroutine, and this value is reassigned to the variable in the
CALL statement GLOBAL.
Содержание Axcess
Страница 1: ...instruction manual Software Axcess Programming Language ...
Страница 8: ...vi Axcess Programming Language Table of Contents ...
Страница 12: ...Introduction 4 Axcess Programming Language ...
Страница 22: ...Axcess Basics 14 Axcess Programming Language ...
Страница 38: ...Channel Characteristics 30 Axcess Programming Language ...
Страница 54: ...Levels 46 Axcess Programming Language ...
Страница 62: ...Operators 54 Axcess Programming Language ...
Страница 66: ...Variable Types and Conversions 58 Axcess Programming Language ...
Страница 70: ...Two Dimensional Arrays 62 Axcess Programming Language ...
Страница 80: ...While Keywords 72 Axcess Programming Language ...
Страница 86: ...Using Buffers 78 Axcess Programming Language ...
Страница 94: ...Waits and Timer Keywords 86 Axcess Programming Language ...
Страница 102: ...Using Subroutines 94 Axcess Programming Language ...
Страница 108: ...Include Files and System_Calls 100 Axcess Programming Language ...
Страница 120: ...Compiler Error Messages 112 Axcess Programming Language ...
Страница 124: ...The External_Control Protocol 116 Axcess Programming Language ...
Страница 143: ...Index 135 Axcess Programming Language ...