LBound 函数 (Visual Basic)

更新:2007 年 11 月

返回数组的指示维度的最小可用下标。

Public Function LBound( _
   ByVal Array As System.Array, _
   Optional ByVal Rank As Integer = 1 _
) As Integer

参数

  • Array
    必选。任何数据类型的数组。希望在其中找到维度的最小可能下标的数组。

  • Rank
    可选。Integer。要返回的最小可能下标的维度。对第一维使用 1,对第二维使用 2,依此类推。如果省略 Rank,则假定为 1。

返回值

Integer。指定的维度的下标可以包含的最小值。只要 Array 已经初始化,即使它没有元素(如它是零长度字符串),LBound 也将始终返回 0。如果 Array 为 Nothing,则 LBound 将引发 ArgumentNullException

异常

异常类型

错误号

条件

ArgumentNullException

9

Array 为 Nothing。

RankException

9

Rank < 1 或 Rank 大于 Array 的秩。

如果正在升级使用无结构错误处理的 Visual Basic 6.0 应用程序,请参见“错误号”一列。(您可以根据 Number 属性(Err 对象)比较错误号。)然而,如果可能,应当考虑用 Visual Basic 的结构化异常处理概述替换这种错误控制。

备注

由于数组下标从 0 开始,因此每一维度最小可用的下标总是为 0。

对于具有以下维度的数组,LBound 返回下表中的值:

Dim a(100, 5, 4) As Byte

调用 LBound

返回值

LBound(a, 1)

0

LBound(a, 2)

0

LBound(a, 3)

0

示例

下面的示例使用 LBound 函数确定数组的指示维度的最小可用下标。

Dim lowest, bigArray(10, 15, 20), littleArray(6) As Integer
lowest = LBound(bigArray, 1)
lowest = LBound(bigArray, 3)
lowest = LBound(littleArray)
' All three calls to LBound return 0.

要求

命名空间:Microsoft.VisualBasic

**模块:**Information

**程序集:**Visual Basic 运行库(在 Microsoft.VisualBasic.dll 中)

请参见

参考

UBound 函数 (Visual Basic)

Dim 语句 (Visual Basic)

ReDim 语句 (Visual Basic)

ArgumentException

RankException