How do you test an array for dimensions?

Results 1 to 3 of 3

Thread: How do you test an array for dimensions?

  1. #1
    Join Date
    Dec 1969

    Default How do you test an array for dimensions?

    Given an array of n dimensions, is there a way to test the array to figure out the number of dimensions?<BR><BR>For instance, if we have this 5 dimensional array:<BR><BR> dim a(6,2,5,2,9)<BR><BR>Is there a function available that would return 5?<BR><BR>Something like:<BR><BR> &#039This would set n = 5<BR> n = dimNum(a)<BR> <BR>I&#039ve looked around a bit, but haven&#039t seen anything on this topic.<BR><BR>Much thanks,<BR>John

  2. #2
    Join Date
    Dec 1969

    Default RE: How do you test an array for dimensions?

    How about this:<BR><BR>&#060;%<BR>Function dimCount( ByRef ar )<BR>&nbsp; &nbsp; For i = 1 To 100<BR>&nbsp; &nbsp; &nbsp; &nbsp; bound = -1<BR>&nbsp; &nbsp; &nbsp; &nbsp; On Error Resume Next<BR>&nbsp; &nbsp; &nbsp; &nbsp; bound = UBound( ar, i )<BR>&nbsp; &nbsp; &nbsp; &nbsp; On Error GoTo 0<BR>&nbsp; &nbsp; &nbsp; &nbsp; If bound = -1 Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dimCount = i - 1<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit Function<BR>&nbsp; &nbsp; &nbsp; &nbsp; End If<BR>&nbsp; &nbsp; Next<BR>&nbsp; &nbsp; dimCount = -1 &#039 impossible!<BR>End Function<BR>%&#062;<BR><BR>Note that this will return 0 if the given argument is *NOT* an array! (Because the UBound will fail for i=1, of course.) And -1 if I screwed up something.<BR><BR>

  3. #3
    Richard A. Lowe Guest

    Default JScript to the rescue...

    Include this and call CountDims() passing it an array:<BR><BR>&#060;script language="JScript" runat="server"&#062;<BR>&nbsp;&nbsp;&nbsp;function CountDims(arrVBArray) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return arrVBArray.dimensions();<BR>&nbsp;&nbsp;&nbsp;}<BR >&#060;/script&#062;

Posting Permissions

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