CountOfElements: Get number of ARRAY elements (S7-1200, S7-1500) - STEP 7

FBD (S7-1200, S7-1500)

ft:publication_title
FBD (S7-1200, S7-1500)
Product
STEP 7
Version
V20
Publication date
11/2024
Language
en-US
CountOfElements: Get number of ARRAY elements

Description

You use the "Get number of ARRAY elements" instruction to query how many ARRAY elements a tag to which "IN" points has.

If it is a single-dimensional ARRAY, the number of ARRAY elements is output as the result. (The difference between the high and low limit +1). If it is a multi-dimensional ARRAY, the number of all dimensions is output as the result.

If you want to query the elements of an ARRAY DB, you should use the instructions "ReadFromArrayDB" or "WriteFromArrayDB", because here a more precise error evaluation for the number of elements is possible.

Note

Instances

The pointer at the "IN" parameter cannot point to an instance and therefore cannot point to a multi-instance or ARRAY of multi-instances.

Note

ARRAY within a data block

If you want to query the number of the elements of an ARRAY which is located in a data block, the block attribute "Data block write-protected in the device" must not be activated in this block. Otherwise, the RET_VAL parameter returns the result "0", irrespective of how many elements the ARRAY contains.

The result is also "0" if the VARIANT or ResolvedSymbol tag is not an ARRAY.

If the tag at the "IN" parameter points to an ARRAY of BOOL, the fill elements are included in the count. (For example, 8 is returned for an ARRAY[0..1] of BOOL).

Enable output ENO returns the signal state "0" if one of the following conditions applies:

  • Enable input EN has the signal state "0".

  • The tag at the "IN" parameter is not an ARRAY. (The result is "0".)

Parameters

The following table shows the parameters of the "Get number of ARRAY elements" instruction:

Parameters

Declaration

Data type

Memory area

Description

EN

Input

BOOL

I, Q, M, D, L or constant

Enable input

ENO

Output

BOOL

I, Q, M, D, L

Enable output

IN

Input

VARIANT, ResolvedSymbol

L (The declaration is possible in the "Input", "InOut" and "Temp" sections of the block interface.)

Tag to be queried

RET_VAL

Output

UDINT

I, Q, M, D, L

Result of the instruction

You can find more information on the valid data types under "See also".

Example

The following example shows how the instruction works:

If the "TagIn" operand returns signal state "1", the instruction is executed. The number of the ARRAY elements of the tag to which the "IN" parameter at the #TagIn_Source operand points is read and output at the "TagOut_RetVal" operand.