Share via


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.

需求

命名空間 (Namespace)︰Microsoft.VisualBasic

**模組︰**Information

組件 (Assembly):Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

請參閱

參考

UBound 函式 (Visual Basic)

Dim 陳述式 (Visual Basic)

ReDim 陳述式 (Visual Basic)

ArgumentException

RankException