Local Variables And Parameters; Local Variables; Parameters - AMX AXCESS CONTROL SYSTEM PROGRAM Instruction Manual

Programming language
Table of Contents

Advertisement

Using Subroutines

Local Variables and Parameters

Two features that expand on the functionality of subroutines are local variables and parameters.
Using these features can help simplify your programs, add more power to your code, and make
your program easier to read and understand.

Local Variables

The first of these two features is the local variable. A local variable is a variable which is declared
inside a DEFINE_CALL and can only be used inside that same DEFINE_CALL. Variables
declared in the main DEFINE_VARIABLE section are called global variables. The words local and
global refer to a variable's scope, which is the part of the program that can access the variable.
Global variables have global scope; that is, the entire program has access to them. A local variable
has local scope, and can only be accessed inside the DEFINE_CALL in which it is declared. Here
is an example of a local variable declaration:
DEFINE_CALL 'TEST CALL'
LOCAL_VAR
{
}
This section of code defines the subroutine 'TEST CALL'. It then declares two local variables,
LOC_VAR (a simple variable) and LOC_ARRAY (an array with a storage capacity of 10). Local
variables are defined after the DEFINE_CALL and before the first open brace, with the keyword
LOCAL_VAR preceding the block of local variables defined. Nowhere else in the program can any
code access the two variables LOC_VAR and LOC_ARRAY, since they are local to the subroutine
'TEST CALL'.
A local variable can have the same name as a local variable in another subroutine. If another
subroutine declares a local variable LOC_VAR, that subroutine will use its LOC_VAR and 'TEST
CALL' will use its own LOC_VAR.
A local variable can also have the same name as a global variable. The local variable takes
precedence in its scope, and the global variable is hidden. For instance, if in the previous example
there was a global variable LOC_VAR, the reference in the subroutine still refers to the local
variable. In this case, the global LOC_VAR is hidden from the subroutine.
Local variables are best used in cases where a subroutine needs to use a variable, but no other piece
of code needs it. Local variables are usually temporary flags, loop counters, and other variables a
subroutine may need to do its work.

Parameters

Several Axcess keywords and functions use parameters, such as ATOI and MID_STRING. Your
DEFINE_CALL subroutines can also use parameters. Parameters are variables defined as part of
the DEFINE_CALL declaration that can receive values from and pass back values to the CALL
statement that called the subroutine. Here is an example subroutine declaration using parameters:
90
LOC_VAR
LOC_ARRAY[1Ø]
LOC_VAR = 1
LOC_ARRAY = 'TESTING'
Axcess Programming Language

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the AXCESS CONTROL SYSTEM PROGRAM and is the answer not in the manual?

This manual is also suitable for:

Axcess

Table of Contents