We have to dim the arrays, so...
Dim a(2, 3, 4) As Integer ' Example: a 3-dimensional array
Print UBound(a)
Print UBound(a, 2)
Print UBound(a, 3)
Results:
2
3
4
So using ubound gets the indicies at runtime. What are you looking to use this for?
I mean if you don't do a dim, you just get the default 10 value...
a(1, 1, 1) = 500
Print UBound(a)
Print UBound(a, 2)
Print UBound(a, 3)
Results:
10
10
10
I think what you are getting at is how to determine if the array is multidimensional. Yeah, the Google code should be...
I suppose a way around it is to just assign variables to the array, and track tose instead of doing an error trap...
And maybe I just missed the point entirely. Let me know if that's the case, but this is where my old tired mind wondered off to... and now if you will excuse me, I have my foot caught in a rabbit hole!
Pete
Dim a(2, 3, 4) As Integer ' Example: a 3-dimensional array
Print UBound(a)
Print UBound(a, 2)
Print UBound(a, 3)
Results:
2
3
4
So using ubound gets the indicies at runtime. What are you looking to use this for?
I mean if you don't do a dim, you just get the default 10 value...
a(1, 1, 1) = 500
Print UBound(a)
Print UBound(a, 2)
Print UBound(a, 3)
Results:
10
10
10
I think what you are getting at is how to determine if the array is multidimensional. Yeah, the Google code should be...
Code: (Select All)
Dim a(2, 3, 4) As Integer ' Example: a 3-dimensional array
Print UBound(a)
Print UBound(a, 2)
Print UBound(a, 3)
Dim Shared numDimensions As Integer
On Error GoTo ErrorHandler
Call CountDimensions(a())
End
ErrorHandler:
If Err = 9 Then ' Subscript out of range error
End
Else
Print "An unexpected error occurred: "; Err
End
End If
Sub CountDimensions (arr() As Integer)
numDimensions = 0
Do
numDimensions = numDimensions + 1
' Attempt to get the upper bound of the current dimension
' If this dimension doesn't exist, an error will occur
dummy = UBound(arr, numDimensions)
Print "dummy ="; dummy
Loop
End Sub
I suppose a way around it is to just assign variables to the array, and track tose instead of doing an error trap...
Code: (Select All)
Dim Shared As Integer d1, d2, d3
d1 = 2: d2 = 3
Dim a(d1, d2) As Integer ' Example: a 3-dimensional array
Print "UBound Indicies #1 ="; d1;: If d1 Then Print UBound(a, 1) Else Print
Print "UBound Indicies #2 ="; d2;: If d2 Then Print UBound(a, 2) Else Print
Print "UBound Indicies #3 ="; d3;: If d3 Then Print UBound(a, 3) Else Print
And maybe I just missed the point entirely. Let me know if that's the case, but this is where my old tired mind wondered off to... and now if you will excuse me, I have my foot caught in a rabbit hole!
Pete

