Determining Array-dimensions

1. Christiaan Guest

## Determining Array-dimensions

Is there a good way to determine the number of dimensions within an array?<BR><BR>I don&#039t like this solution:<BR>---------------------------<BR>ON ERROR GOTO OneDimension<BR><BR> intMaxBound = UBOUND(arrArray, 2)<BR> intDimensions = 2<BR><BR>OneDimension:<BR> intDimensions = 1<BR><BR>--------------------------<BR>the script above works with VB, but it&#039s not a good solution since it doesn&#039t check for third, fourth, etc dimensions. I&#039m sure there is another, easier, way, but i don&#039t know how really...<BR><BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## RE: Determining Array-dimensions

I don&#039t know of any builtin function. And since VBS doesn&#039t support On Error GoTo [a specific line] you can&#039t use the trick you suggested, even.<BR><BR>But how about this:<BR>&#060;%<BR>dimCnt = 0<BR>On Error Resume Next<BR>For i = 1 To 100000 &#039 max doesn&#039t matter...you&#039ll error out first!<BR>&nbsp;&nbsp;&nbsp;&nbsp;test = -1<BR>&nbsp;&nbsp;&nbsp;&nbsp;test = UBound( theArray, i )<BR>&nbsp;&nbsp;&nbsp;&nbsp;If test &#060; 0 Then Exit For<BR>&nbsp;&nbsp;&nbsp;&nbsp;dimCnt = i<BR>Next<BR>On Error GoTo 0<BR>%&#062;<BR><BR>You could put the On Error statements *just* around the <BR>&nbsp;&nbsp;&nbsp;&nbsp;test = UBound( theArray, i )<BR>statement, but since the other statements can&#039t generate errors--and since I think the version shown would give a bit better performance--why not do it as shown?<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•