Using Subroutines
89
Axcess Programming Language
Using Subroutines
In larger programs, you may want to break the program into smaller, more manageable parts called
subroutines. A subroutine is a section of code that stands alone and can be called from anywhere
else in the program. The most common usage of subroutines is to execute the same group of
instructions from different places in the program. Using a subroutine allows you to avoid having to
retype those instructions over and over in the program. Instead, you can just call the subroutine.
Defining a Subroutine
In Axcess, subroutines are created using the DEFINE_CALL statement. The subroutine name
follows the DEFINE_CALL keyword, enclosed in single quotes. There are certain restrictions for
subroutine names:
!
They cannot be previously defined contents or variables.
!
They cannot be names that have already been assigned to BUFFERs or WAITs.
!
They are case-sensitive; Test and TEST are not the same.
Subroutines must be defined before they can be used. For this reason, DEFINE_CALLS are usually
found right before the DEFINE_START section of the program. For example:
DEFINE_VARIABLE
LIGHT_PRESET (* CURRENT LIGHTING PRESET *)
DEFINE_CALL 'PRESET LIGHTS' (CARD,PRESET)
{
PULSE[CARD,PRESET]
LIGHT_PRESET = PRESET
}
DEFINE_START
CALL 'PRESET LIGHTS' (LIGHTS,LIGHT_FULL)
DEFINE_PROGRAM
PUSH[TP,7] (* LIGHTS OFF *)
CALL 'PRESET LIGHTS' (LIGHTS,LIGHT_OFF)
[TP,7] = (LIGHT_PRESET = LIGHT_OFF)
Spaces in the subroutine name are allowed, since it is a string literal. The subroutine's code must be
enclosed in braces. Regardless of how long the subroutine is, it must be in this format.
Calling subroutines
To tell Axcess to execute a subroutine, use the CALL keyword and the name of the subroutine in
single quotes. For example, to execute the previous subroutine, type the following where you want
the CALL to occur.
CALL 'LIGHTS OFF'
When Axcess executes the CALL, program execution jumps to the first line inside the braces of the
DEFINE_CALL. The subroutine is executed only once, and then Axcess returns to the statement
directly following the CALL statement.
Содержание 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 ...