Technical data
Appendix
27.3 Data Types and Parameter Types
Programming with STEP 7
Manual, 05/2010, A5E02789666-01 603
Entering Initial Values for an Array
You can assign an initial value to every array element when you create arrays. STEP 7 provides
two methods for entering initial values:
• Entry of individual values: for each element of the array, you specify a value that is valid for the
data type of the array. You specify the values in the order of the elements: [1,1]. Remember
that the individual elements must be separated from each other by a comma.
• Specifying a repetition factor: with sequential elements that have the same initial value, you
can specify the number of elements (the repetition factor) and the initial value for these
elements. The format for entering the repetition factor is x(y), where x is the repetition factor
and y is the value to be repeated.
If you use the array declared in the above figure, you can specify the initial value for all six
elements as follows: 17, 23, -45, 556, 3342, 0. You could also set the initial value of all six
elements to 10 by specifying 6(10). You could specify specific values for the first two elements and
then set the remaining four elements to 0 by specifying the following: 17, 23, 4(0).
Accessing Data in an Array
You access data in an array via the index of the specific element in the array. The index is used
with the symbolic name.
Example: If the array declared in the above figure begins at the first byte of DB20 (motor), you
access the second element in the array with the following address:
Motor.Heat_2x3[1,2].
Using Arrays as Parameters
You can transfer arrays as parameters. If a parameter is declared in the variable declaration as
ARRAY, you must transfer the entire array (and not individual elements). An element of an array
can, however be assigned to a parameter when you call a block, providing the element of the array
corresponds to the data type of the parameter.
If you use arrays as parameters, the arrays do not need to have the same name (they do not even
need a name). Both arrays (the formal parameter and the actual parameter) must however have
the same structure. An array in the format 2 x 3 consisting of integers, for example, can only be
transferred as a parameter when the formal parameter of the block is defined as an array in the
format 2 x 3 consisting of integers and the actual parameter that is provided by the call operation is
also an array in the format 2 x 3 consisting of integers.