Find out number of array dimensions.

Say I have a routine that accepts an array as a parameter, how can I find out the number of dimensions that array is.

i.e. Dim aArray(3,4) As String

Public Sub Foo(aArray() As String)

 If NumOfDims(aArray()) = 2 Then
     
     DoSomething

   Else
     
     DoSomethingElse

 End If

End Sub
LVL 10
Jason EvansSenior Software DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jjmartinCommented:
ubound function:
Returns the largest available subscript for the indicated dimension of an array.


lbound function:
Returns the smallest available subscript for the indicated dimension of an array.
0
caraf_gCommented:
wrong answer.


Private Function ArrayDimensions(arrtest As Variant) As Long

On Error GoTo ExitFun

Dim lngDimensions As Long
Dim lngTest As Long

Do While True
    lngDimensions = lngDimensions + 1
    lngTest = LBound(arrtest, lngDimensions)
Loop

ExitFun:
ArrayDimensions = lngDimensions - 1

End Function

0
caraf_gCommented:

Public Sub Foo(aArray As Variant)

Dim aArray(3,4) As String

 If ArrayDimensions(aArray) = 2 Then
     
     DoSomething

   Else
     
     DoSomethingElse

 End If

End Sub

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

caraf_gCommented:
Sorry, never mind the sub.

Dim aArray(3,4) As String

 If ArrayDimensions(aArray) = 2 Then
       
     DoSomething

   Else
       
     DoSomethingElse

 End If

0
amebaCommented:
caraf_g said the first way (LBound)
but maybe you are brave enough to use the second way:
http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=27
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
caraf_gCommented:
Nice one!
0
amebaCommented:
Must be - comes from Italy. :)
0
Jason EvansSenior Software DeveloperAuthor Commented:
The example code on this site works a treat. Thanks
0
amebaCommented:
Thanks for your points
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.