LENGTH

Use the LENGTH script function to retrieve the size of a script array. The function returns the number of elements in the script array, or the number of filled array elements.

Syntax

LENGTH (script array [,SIZE])

Parameters

  • LENGTH
    Returns the size of the script array

  • Script array
    Name of the script variable that has been defined as an array

  • SIZE
    (Optional) Ignores empty elements at the end of the array
    Note: this parameter only returns the size up to the last filled element if the array has the data type string. All other data types always return the total array size.


Note: The maximum size of a script array is 99999. For more information about script arrays, see Arrays.

Important! A script error occurs if the specified array cannot be found or if you specify a script variable instead of a script array. Ensure that you use empty square brackets to specify your array.

Example

The following example creates a script array, and fills the array with values from a VARA object. The script uses a loop to write the results to the activation report.

:DEFINE &ARRAY#, string, 5
:SET &LEN# = LENGTH(&ARRAY#[])
:SET &VAR# = 1

:FILL &ARRAY#[] = GET_VAR(VARA1, ARRAY)
:WHILE &VAR# LE &LEN#
:PRINT "Element &VAR# = &ARRAY#[&VAR#]"
:SET &VAR# = &VAR# + 1
:ENDWHILE

See also: