UBound (function)


UBound(ArrayVariable() [,dimension])


Returns an Integer containing the upper bound of the specified dimension of the specified array variable.


The dimension parameter is an integer that specifies the desired dimension. If not specified, then the upper bound of the first dimension is returned.

The UBound function can be used to find the upper bound of a dimension of an array returned by an OLE automation method or property:

  UBound(object.property [,dimension])

  UBound(object.method [,dimension])


This example dimensions two arrays and displays their upper bounds.

Const crlf = Chr$(13) + Chr$(10)

Sub Main()
  Dim a(5 To 12)
  Dim b(2 To 100,9 To 20)
  uba = UBound(a)
  ubb = UBound(b,2)
  MsgBox "The upper bound of a is: " & uba & crlf & " The upper bound of b is: " & ubb


This example uses Lbound and Ubound to dimension a dynamic array to hold a copy of an array redimmed by the FileList statement.

  Dim fl$()

  FileList fl$,"*"
  count = Ubound(fl$)
  If ArrayDims(a) Then
    Redim nl$(Lbound(fl$) To Ubound(fl$))
    For x = 1 To count
      nl$(x) = fl$(x)
    Next x
    MsgBox "The last element of the new array is: " & nl$(count)
  End If
End Sub

See Also

LBound (function); ArrayDims (function); Arrays (topic).

More information