Category: Runtime Helpers
ArrayLen(arrayReference)
ArrayLen(arrayReference, dimension As Integer)
Integer
Returns the size of an array.
When you pass only the array, ArrayLen returns the total number of elements across all dimensions.
When you pass a second argument, it returns the length of one specific dimension. The dimension value is zero-based, so the first dimension is 0, the second is 1, and so on.
Array dimensions in LunarBasic are declared using element counts, so Dim values(3, 4) creates an array with lengths 3 and 4. Its total element count is therefore 12.
The first argument must be an array reference. Passing a non-array value is an error.
The first argument may also be an array field on a user-defined object, such as ArrayLen(player.InventorySlots).
Dim values(3, 4) As Integer
Dim total As Integer
Dim columns As Integer
total = ArrayLen(values)
columns = ArrayLen(values, 1)
After these calls, total is 12 and columns is 4.