6-49
6 Programming
NJ-series CPU Unit Software User’s Manual (W501)
6-3 Variables
6
6-3-7 Array Specifications and Range Specifications for Data Types
You can specify the following attributes for variables with each data types.
• Array specifications
• Range specifications
Use an array specification for a data type that handles a group of data with the same attributes as a sin-
gle entity. You can use an array specification for the basic data types and derivative data types. Arrays
are useful when you want to handle multiple pieces of data together as you would, for example, coordi-
nate values for motion control.
Expressing Arrays and Array Elements
Specifying Elements
The individual pieces of data that make up an array are called “elements.”
The elements of an array are expressed by adding a subscript (element number) from the start of
the array to the name of the variable that represents the entire array.
Enclose the subscript in single-byte braces []. Subscripts can be either constants or variables. In ST,
you can also use expressions to express subscripts.
Examples:
x:=10;
Mem[x]: This expression specifies the xth element of the array variable Mem (the variable x
has a value of 10, so this would point to the 10th element).
x:=10;
y:=20;
Data[x+y]: This expression specifies the x+yth element of the array variable Data (the variable
x has a value of 10 and variable y has a value of 20, so this would point to the 30th element).
Specifying An Array (i.e., the Entire Array)
The array represents all elements that make up the array. Arrays are expressed by the name of the
array variable. In the above examples, the arrays are written as Mem and Data.
Creating an Array
1
Enter “A” into the Data Type Column of the variable table and select ARRAY[?..?] OF ? from the
list of possible data type name candidates.
2
Enter the number of the first element in the array for the left question mark and the last number
for the right question mark in the “[?..?]” section. Next, enter the data type for the question mark
in the “OF ?” section and register the variable.
6-3-7 Array Specifications and Range Specifications for Data Types
Array Specifications (ARRAY[]OF)
ARRAY[0..99] OF INTMem
Data type
Variable name
Variable Table
ARRAY[0..99] OF INTData
Data type
Variable name
Variable Table