Arrays and Strings
35
Axcess Programming Language
PRESETS = 'FOUR (* LENGTH = 4 *)
PRESETS = 'ONE' (* LENGTH = 3 *)
PRESETS = "12,5,'123'" (* LENGTH = 5 *)
PRESETS = "PLAY,5,Ø,'NO',X" (* LENGTH = 6 *)
The length of a string array cannot exceed the number of storage locations allocated to it in the
DEFINE_VARIABLE section. For example, if the string GOODBYE is placed in the
CAM_PRESETS variable, the array will only contain the string GOODBY, dropping the final E
because CAM_PRESETS was defined to hold a maximum of six locations. The length of
CAM_PRESETS would also be set to 6. If you attempt to assign an array that exceeds the storage
allocations, the system will generate a run time error message: BAD SET LENGTH.
When string literals and string expressions are assigned, the the length of the string array is
automatically set to the length of the string literal or string expression being assigned to it.
However, assigning values to individual elements of an array does not affect the length value of the
array. For instance, if the letters W, O, R, and D are assigned individually to elements of
CAM_PRESETS, as shown below, the length will not change; if the length was previously 3, it will
still be 3.
PRESETS[1] = 'W'
PRESETS[2] = 'O'
PRESETS[3] = 'R'
PRESETS[4] = 'D'
The SET_LENGTH string keyword explicitly sets the string length value of an array variable. For
instance, to set the length value of CAM_PRESETS to 4, you would use the statement:
SET_LENGTH_STRING(CAM_PRESETS,4)
String lengths play an important role in the handling of strings. The following string expression
contains an array:
NEW_STRING = "5,TEMP,'GO'"
As Axcess constructs a string from this expression, the number of characters from NEW_STRING
it adds will equal the TEMP string's length value. If TEMP contains 1, 2, 3, 4, 5, 6, but its string
length value is 3, the resulting string from the above string expression will look like the following
example:
TEMP[1] = 1
TEMP[2] = 2
TEMP[3] = 3
TEMP[4] = 4
TEMP[5] = 5
TEMP[6] = 6
SET_LENGTH_STRING(TEMP,3)
NEW_STRING = "5,TEMP,'GO'" (* NEW_STRING now equals "5,1,2,3,'G','O'" *)
The array string length is important to many Axcess string operations. This value determines how
much of the string is used when the entire array is referenced. Knowing this will prevent subtle
errors in your code. For instance, if you assign values to individual elements in an array, and then
assign that array to another, nothing is copied. For example:
Содержание 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 ...