UBound 函数UBound function

返回包含指定的数组维度的最大可用下标的Long数据类型。Returns a Long data type containing the largest available subscript for the indicated dimension of an array.

语法Syntax

UBound(arrayname, [ dimension ])UBound(arrayname, [ dimension ])


UBound函数的语法包含这些部分。The UBound function syntax has these parts.

PartPart 说明Description
arraynamearrayname 必需。Required. 数组变量的名称;遵循标准变量命名约定。Name of the array variable; follows standard variable naming conventions.
维度dimension 可选;Variant (Long)。Optional; Variant (Long). 指示返回哪一个维度的上限的整数。Whole number indicating which dimension's upper bound is returned. 对第一个维度使用 1,对第二个维度使用 2,依此类推。Use 1 for the first dimension, 2 for the second, and so on. 如果省略 dimension,则假定为 1。If dimension is omitted, 1 is assumed.

备注Remarks

UBound函数与**LBound** 函数结合使用, 以确定数组的大小。The UBound function is used with the LBound function to determine the size of an array. 使用 LBound 函数可查明数组维度的下限。Use the LBound function to find the lower limit of an array dimension.

UBound 为具有这些维度的数组返回以下值:UBound returns the following values for an array with these dimensions:

语句Statement 返回值Return Value
UBound(A, 1) 100100
UBound(A, 2) 第三章3
UBound(A, 3) 44

示例Example

此示例使用 UBound 函数确定数组的指定维度的最大可用下标。This example uses the UBound function to determine the largest available subscript for the indicated dimension of an array.

Dim Upper
Dim MyArray(1 To 10, 5 To 15, 10 To 20)    ' Declare array variables.
Dim AnyArray(10)
Upper = UBound(MyArray, 1)    ' Returns 10.
Upper = UBound(MyArray, 3)    ' Returns 20.
Upper = UBound(AnyArray)      ' Returns 10.

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.