Elem_OfArray1D

Number of elements in an array

This function yields the number of elements in an array.

The total number of elements of the array variable at input Array1D is yielded at output NrOfElem1. An array variable of any dimension preferred can be transferred. In any case, the total number of elements of all dimensions is returned. Hence, functions and function blocks can be written that process arrays of various lengths (also in conjunction with the functions (GetPointer, AreaOffs_ToVar,Var_ToAreaOffs).

Parameters

Input

Array1D (ANY_IN_UNITS_OF_WORDS)

Input variable (array dimension 1,2 or 3) whose number of elements is to be determined

Output

NrOfElem1 (INT, DINT, UINT, UDINT)

Yields number of elements in the input variable

Example

POU header

All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.

	VAR
		ArrayOfInt: ARRAY [2..15] OF INT:=[14(0)];
		NumberOfDim1: INT:=0;
	END_VAR

POU body

In this case the function Elem_OfArray1D is executed in each CPU cycle (no EN input). It determines the number of elements of the variable ArrayOfInt. The result here is: NumberOfDim1 = 14.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,Elem_OfArray1D!,Instance,8,1,19,4,,?DArray1D?CNrOfElem1);
B(B_VARIN,,ArrayOfInt,6,2,8,4,);
B(B_VAROUT,,NumberOfDim1,19,2,21,4,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

Further example projects (directory "Samples" of FPWIN Pro installation):Calculate the sum of all array elements

Modified on: 2019-01-26Feedback on this pagePanasonic hotline