Results 1 to 4 of 4

Thread: Getting the Ubound from a second or third dimension

  1. #1

    Thread Starter
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238

    Getting the Ubound from a second or third dimension

    I have a three dimensional array, but the the second and third dimensions are all different sizes.
    like:
    anArray(0,0 to 8)
    anArray(1,0 to 12)
    When you say Ubound(anArray), it would return 1 (for this case). But say I want to get the second dimension Ubound for each of the first dimensions?
    this doesn't work (as far as i know): ubound(anArray(0)) (under my assumption this would return 8, but like i said, it doesn't work).
    Please tell me something that does work.
    thanks,
    jmiller

  2. #2
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    VB Code:
    1. Dim anArray(0,0 to 8)
    2. Dim anOtherArray(1,0 to 12)
    3.  
    4. 'Syntax is Ubound(Variable,Dimension) or Lbound(Variable,Dimension)
    5.  
    6. Debug.Print Ubound(anArray,1) 'Returns 0
    7. Debug.Print LBound(anArray,1) 'Returns 0
    8. Debug.Print UBound(anArray,2) 'Returns 8

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  3. #3
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    UBound Function


    Returns aLong containing the largest available subscript for the indicated dimension of anarray.

    Syntax

    UBound(arrayname[, dimension])

    The UBound function syntax has these parts:

    Part Description
    arrayname Required. Name of the arrayvariable; follows standard variable naming conventions.
    dimension Optional; Variant (Long). Whole number indicating which dimension's upper bound is returned. Use 1 for the first dimension, 2 for the second, and so on. If dimension is omitted, 1 is assumed.


    Remarks

    The UBound function is used with the LBound function to determine the size of an array. Use the LBound function to find the lower limit of an array dimension.

    UBound returns the following values for an array with these dimensions:

    Dim A(1 To 100, 0 To 3, -3 To 4)
    Statement Return Value
    UBound(A, 1) 100
    UBound(A, 2) 3
    UBound(A, 3) 4
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4

    Thread Starter
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238
    Thanks alot!
    jmiller

Posting Permissions

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



Click Here to Expand Forum to Full Width