UBound Function


UBound Function

Class

VisualBasic.Information

Syntax

     Dim result As Integer = UBound(array[, rank]) 


array (required; any)

An array with an upper bound that is to be determined.


rank (optional; Integer)

The dimension to assess for an upper bound. If omitted, it defaults to 1.

Description

The UBound function returns the upper limit of the specified dimension of an array.

Usage at a Glance

  • If array is uninitialized, UBound generates a runtime error. Compare array to Nothing to prevent this error:

         If (someArray IsNot Nothing) Then        ' ----- OK to use UBound 

  • Since the lower bound of .NET arrays is always 0, the number of items in an array dimension is always UBound(array, rank) + 1.

Version Differences

The 2005 release of Visual Basic supports a new array declaration syntax that restores the VB 6 style "lower To upper" syntax, as in:

     Dim someArray(0 To 5) As String 

However, the specified lower bound must still be 0.

See Also

LBound Function




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net