Skip to Content
VB.NET Language in a Nutshell, Second Edition
book

VB.NET Language in a Nutshell, Second Edition

by Steven Roman PhD, Ron Petrusha, Paul Lomax
April 2002
Intermediate to advanced
688 pages
19h 51m
English
O'Reilly Media, Inc.
Content preview from VB.NET Language in a Nutshell, Second Edition

Name

UBound Function

Class

Microsoft.VisualBasic.Information

Syntax

UBound(array[, rank])
array (required; any)

The name of the array

rank (optional; Integer)

A number specifying the dimension of the array

Return Value

Integer

Description

Indicates the upper limit of a specified coordinate of an array. The upper boundary is the largest subscript you can use with that coordinate.

Rules at a Glance

  • To determine the upper limit of the first coordinate of an array, set rank to 1, set it to 2 for the second coordinate, and so on.

  • If rank is not specified, 1 is assumed.

  • The function returns -1 if the array is uninitialized.

Programming Tips and Gotchas

  • Note that UBound returns the actual subscript of the upper bound of a particular array dimension.

  • The number of valid indices for the ith coordinate is equal to UBound(array, i) + 1.

  • If array is an uninitialized array, passing it to the UBound function generates an ArgumentNullException exception. To prevent this, you can declare the array as follows:

    Dim arrValues(-1) As String
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

VB .NET Language in a Nutshell

VB .NET Language in a Nutshell

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596003080Supplemental ContentCatalog PageErrata