O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

UBound Function

Syntax

UBound(arrayname[, dimension])
arrayname

Use: Required

An array variable or an expression that evaluates to an array.

dimension

Use: Optional

Data Type: Long

A number specifying the dimension of the array.

Return Value

A Long.

Description

Indicates the upper limit of a specified dimension of an array. The upper boundary is the largest subscript you can access within the specified array.

Rules at a Glance

  • If dimension isn’t specified, 1 is assumed. To determine the upper limit of the first dimension of an array created by VBScript code, set dimension to 1, set it to 2 for the second dimension, and so on.

  • The upper bound of an array dimension can be set to any integer value using Dim, Private, Public, and Redim.

Programming Tips and Gotchas

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

  • UBound is especially useful for determining the current upper boundary of a dynamic array.

  • The UBound function works only with conventional arrays. To determine the upper bound of a collection object, retrieve the value of its Count or Length property.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required