Click or drag to resize

ALenT Function (Array OfT)

Return the number of elements in an array.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.4a
Syntax
 FUNCTION ALen<T>(
	aTarget AS ARRAY OF<T>
)
WHERE T : NEW()
 AS DWORD
View Source

Parameters

aTarget
Type: Array OfT
The array to count.

Type Parameters

T
The type of the array elements

Return Value

Type: UInt32
The number of elements in the array.
If the array is empty, ALen() returns 0.
Remarks
If the array is multidimensional, subarrays count as one element.
This means that the ALen() of a multidimensional array simply returns the length of the first dimension.
To determine the number of elements in other dimensions, use ALen() on the subarrays, as shown in the example below.  (Note that multidimensional arrays in X# need not have uniform dimensions.)
Examples
This example creates a literal 2-dimensional array, then returns the array and the number of elements in the subarray that is contained in the first element of the array:
X#
1LOCAL aArray := {{1, 2}, {1, 2}, {1, 2}}
2? ALen(aArray)                                // 3
3? ALen(aArray[1])                            // 2
This example navigates a multidimensional array using ALen():
X#
 1LOCAL aArray := {{1, 2}, {1, 2}, {1, 2}}
 2LOCAL nRow, nColumn AS SHORTINT
 3LOCAL nRowCount, nColumnCount AS SHORTINT
 4nRowCount = ALen(aArray)
 5FOR nRow := 1 UPTO nRowCount
 6    nColumnCount = ALen(aArray[nRow])
 7    FOR nColumn := 1 UPTO nColumnCount
 8        ? nRow, nColumn, aArray[nRow][nColumn]
 9    NEXT
10NEXT
In this example, a function returns an array of numeric values that describe the dimensions of a multidimensional array.
The function assumes that the array has uniform dimensions:
X#
1FUNCTION Dimensions(aArray)
2    LOCAL aDims := {}
3    DO WHILE IsArray(aArray)
4        AADD(aDims, ALen(aArray))
5        aArray := aArray[1]
6    ENDDO
7    RETURN (aDims)
See Also