UBOUND

UBOUND(arrayname [,dimension])

Returns the upper limit in a given dimension of an array (Long).


arraynameThe array (Variant).
dimension(Optional) The number of the dimension to use (Long).

REMARKS
* You cannot prefix this function with "VBA."
* This function should not be used to find the size of an array because it all depends on the lower limit.
* To calculate the size of an array, you need to subtract the LBOUND away from the UBOUND and add ONE.
* If "dimension" = 1, then the first dimension of the array is used.
* If "dimension" = 2, then the second dimension of the array is used.
* If "dimension" is left blank, then 1 is used.
* You can use the LBOUND function to return the lower limit in a given dimension of an array.
* The equivalent .NET function is Microsoft.VisualBasic.Information.UBound
* This function is not available in Access.
* For the Microsoft documentation refer to learn.microsoft.com

Dim aValues(10) As Double 
Debug.Print UBound(aValues) '= 10, array has 11 items (0,1,2,3,4,5,6,7,8,9,10)

Dim aValues(1 To 10) As Double
Debug.Print UBound(aValues) '= 10, array has 10 items (1,2,3,4,5,6,7,8,9,10)

Dim aValues(5 To 10) As Double
Debug.Print UBound(aValues) '= 10, array has 6 items (5,6,7,8,9,10)

Dim aValues(5 To 10) As Double
Debug.Print "Size of array is: "
Debug.Print UBound(aValues) - LBound(aValues) + 1

Dim avTemporary(1 To 100, 0 To 3, -3 To 4) As String
Debug.Print UBound(avTemporary) '= 100
Debug.Print UBound(avTemporary, 1) '= 100
Debug.Print UBound(avTemporary, 2) '= 3
Debug.Print UBound(avTemporary, 3) '= 4

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top