Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

傳回一個 Long,其中包含 陣列指定維度的最大可用下標。

語法

UBound ( arrayname [, dimension ] )

UBound 函數語法具有下列自變數:

引數

描述

arrayname

必要。 陣列 變數的名稱 ;遵循標準變數命名慣例。

維度

選擇性。 Variant (Long) 。 指出傳回哪個維度上限的整數。 第一個維度使用 1,第二個維度使用 2,依此類型。 如果 省略維度 ,則會假設為1。


註解

UBound 函數與 LBound 函數搭配使用,以決定數位的大小。 使用 LBound 函數尋找數位維度的下限。

UBound 會 針對具有下列維度的陣列數組傳回下列值:

Dim A(1 To 100, 0 To 3, -3 To 4)

聲明

傳回值

UBound(A, 1)

100

UBound(A, 2)

3

UBound(A, 3)

4


範例

附註: 下列範例示範如何在 Visual Basic for Applications (VBA) 模組中使用此函數。 如需使用 VBA 的詳細資訊,請在 [搜尋] 旁的下拉式清單中選取 [開發人員參考],並在 [搜尋] 方塊中輸入一個或多個字詞。

此範例使用 UBound 函數來判斷陣列所指定維度的最大可用下標。

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

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×