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
| Parameter | Description | Format |
|---|---|---|
| Script array | Defines the name of the script variable that has been defined as an array. | Script 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. |
Script keyword |
Important Considerations
Key considerations include:
-
The maximum size of a script array is 99999.
-
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.
Return Codes
The LENGTH function returns the size of the script array as a number.
Examples
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
Related Topics
See also:
seealso