Arrays and Strings
In this section arrays and strings will be introduced. Understanding these concepts and the
associated keywords will allow you to easily handle data, and will provide another means of
communicating with the outside world.
Defining Arrays
In the program developed in the previous sections, you used a variable. A variable can only hold
one value at a time. However, if you need a variable to hold several values at once, you can use an
array. An array is a single variable that has more than one storage location.
Arrays must be defined as variables in the DEFINE_VARIABLE section of your program. Its
definition has two parts: a unique identifier and its storage capacity. First, the variable must be
named by a valid identifier.
Second, the number of storage locations in the array must be indicated. A maximum of 255
locations can be specified, and each location holds a value from 0 to 255.
For more information on identifiers, refer to Identifiers on page 7.
For your new program, you want to store several preset levels for the volume control card. You
could create several individual variables and use IF statements or SELECT...ACTIVE statements to
select the preset you want to use. Or even better, you could create an array and use the index value
(explained below) to pick the preset you want to use. Here is your array declaration:
DEFINE_VARIABLE
CAM_PRESETS[6]
This declares a new variable, PRESETS, which is shown in FIG. 6. The variable CAM_PRESETS
is an array which can hold six distinct values, as defined by the number 6 inside the brackets.
FIG. 6 The array CAM_PRESETS has six empty storage locations
Accessing and Storing Array Values
To access a particular value in an array, refer to the storage location inside the array you wish to
retrieve, as shown in the example below:
DEFINE_PROGRAM
CAM_PRESET_1 = CAM_PRESETS[3]
The number inside the brackets is called the index value. The index value is the number that tells
Axcess which location in the array to retrieve, and it must be a number from 1 to 255. This example
assigns the value in the third location of CAM_PRESETS to the variable CAM_PRESET_1.
Retrieving a value from an array does not change the array (see FIG. 7).
Axcess Programming Language
Arrays and Strings
31
Need help?
Do you have a question about the AXCESS CONTROL SYSTEM PROGRAM and is the answer not in the manual?