ArraySize

(Engine-Level Function)

Description: Returns the number of elements in an array dimension.
Returns: Numeric
Usage: Script or steady state.
Function Groups: Array
Related to: ArrayDimensions | ArrayStart | Array Functions
Format: ArraySize(Array[, Dimension])
Parameters:  
Array
Required. Any array variable.
Dimension
Optional. Any numeric expression that gives the array dimension to measure starting at 0 (the left-most dimension in a multi-dimensional array). Defaults to zero.
Comments: If Array is a variable rather than an array, return value will be invalid.
This function is useful for writing intelligent parameterized modules. The module can determine how many elements there are in an array that is passed to it.

Example 1:

  MyArray = new[10];
  ...
  Size = ArraySize(MyArray);

In this example, Size will receive the value 10.

 

Example 2:

[
  A;
  X;
  Y;
  Z;
]
Init[
  If 1 Main;
  [
    A = New(2,3);
    ArrayOp1(A[0][0], 3, 0, 0);
    ArrayOp1(A[1][0], 3, 0, 0);
  ]
]
Main [
  X = ArraySize(A)
  Y = ArraySize(A,0);
  Z = ArraySize(A,1);
]

In this example, A will be as follows:

X will be 2

Y will be 2

Z will be 3