Ubound a 2D array

Results 1 to 4 of 4

Thread: Ubound a 2D array

  1. #1
    Phoebe Guest

    Default Ubound a 2D array

    Hi All,<BR>If I have declared an array <BR>Redim x(A,B)<BR>that is with a 2D array of row size of A and column size of B <BR>I use UBound(A) ,it only returns the row size A.<BR>If I wanna show the size of one row,just like <BR>UBound(x(A))<BR>or <BR>UBound(x(A,0))<BR>which I expected to return B,that is the column size. <BR>But both fails,Can Anyone Help ?

  2. #2
    Skippie Guest

    Default Ubound a 2D array answer

    This is clunky, but it works. However, the maximum size is<BR>65536. You may increase it by setting variable i to a higher<BR>binary number (keep multiplying it by 2). <BR><BR><BR>&#060;%<BR> Dim a(16,115)<BR><BR> Response.Write(UBound2(a))<BR><BR><BR> Function UBound2(a)<BR> Dim b,i,x,go,e1,e2<BR> <BR> i = 65536<BR> b = i<BR> go = True<BR><BR> Do While go = True AND b &#062; 1<BR> b = b / 2<BR> <BR> On Error Resume Next<BR> x = a(0,i)<BR> e1 = Err.Number<BR> <BR> If e1 &#060;&#062; 0 Then<BR> i = i - b<BR> Else <BR> On Error Resume Next<BR> x = a(0,i+1)<BR> e2 = Err.Number<BR> If e2 = 0 Then<BR> i = i + b<BR> Else<BR> go = False<BR> End If <BR> End If<BR> Loop<BR> <BR> UBound2 = i <BR> End Function<BR><BR>%&#062;<BR><BR><BR><BR>-- Skippie

  3. #3
    Join Date
    Dec 1969

    Default RE: Ubound a 2D array

    UBound(x,1) - this would give u the upperbound of the row (A)<BR>UBound(x,2) - would give u upperbound of the column (B)<BR><BR>syntax for UBound function is UBound(arrayname[,dimension])<BR>thus, if dimension is 1 the function returns the size of the first dimension. See MSDN Library reference for more details

  4. #4
    Skippie Guest

    Default Thanks for the info...

    At least I got some excercise in writing a binary search.<BR><BR><BR>I also found out that everytime you write:<BR><BR>On Error Resume Next<BR><BR>it resets Err.Number to 0.<BR><BR><BR>-- Skippie

Posting Permissions

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