Information.UBound 方法
傳回所指示的陣列維度之可用的最高註標。
命名空間: Microsoft.VisualBasic
組件: Microsoft.VisualBasic (在 microsoft.visualbasic.dll 中)
語法
'宣告
Public Shared Function UBound ( _
Array As Array, _
<OptionalAttribute> Optional Rank As Integer = 1 _
) As Integer
'用途
Dim Array As Array
Dim Rank As Integer
Dim returnValue As Integer
returnValue = Information.UBound(Array, Rank)
public static int UBound (
Array Array,
[OptionalAttribute] int Rank
)
public:
static int UBound (
Array^ Array,
[OptionalAttribute] int Rank
)
public static int UBound (
Array Array,
/** @attribute OptionalAttribute() */ int Rank
)
public static function UBound (
Array : Array,
Rank : int
) : int
參數
- Array
必要項。任何資料型別的陣列,您想在該陣列中找到維度的最高可能註標。
- Rank
選擇項。Integer。要傳回可能之最高註標所針對的維度。使用 1 表示第一個維度,2 表示第二個維度,依此類推。如果省略了 Rank,則假設為 1。
傳回值
Integer - 指定之維度的註標可以包含的最高值。如果 Array 只有一個元素,則 UBound 會傳回 0;如果 Array 沒有任何元素 (例如,它是長度為零的字串),則 UBound 會傳回 -1。
備註
如需詳細資訊,請參閱 Visual Basic 的主題 UBound 函式 (Visual Basic)。
由於陣列註標起始為 0,維度的長度比該維度最高的可用註標大一。
若陣列具有下列維度,則 UBound 會傳回下表中的數值:
Dim a(100, 5, 4) As Byte
UBound 的呼叫 |
傳回值 |
---|---|
|
100 |
|
5 |
|
4 |
您可使用 UBound 判斷陣列中的總元素數目,但是您必須調整它傳回的值,讓該值表示註標是從 0 開始的事實。下列範例將計算上面範例中陣列 a
的總大小:
Dim total As Integer
total = (UBound(A, 1) + 1) * (UBound(A, 2) + 1) * (UBound(A, 3) + 1)
針對 total
所計算的值為 3030,也就是 101 * 6 * 5。
範例
下列範例會使用 UBound 函式,以判斷所指示的陣列維度可用的最高註標。
Dim highest, bigArray(10, 15, 20), littleArray(6) As Integer
highest = UBound(bigArray, 1)
highest = UBound(bigArray, 3)
highest = UBound(littleArray)
' The three calls to UBound return 10, 20, and 6 respectively.
平台
Windows 98、 Windows 2000 SP4、 Windows CE、 Windows Millennium Edition、 Windows Mobile for Pocket PC、 Windows Mobile for Smartphone、 Windows Server 2003、 Windows XP Media Center Edition、 Windows XP Professional x64 Edition、 Windows XP SP2、 Windows XP Starter Edition
.NET Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。
版本資訊
.NET Framework
支援版本:2.0、1.1、1.0
.NET Compact Framework
支援版本:2.0、1.0
請參閱
參考
Information 類別
Information 成員
Microsoft.VisualBasic 命名空間
ArgumentException
RankException
其他資源
UBound 函式 (Visual Basic)
LBound 函式 (Visual Basic)
Dim 陳述式 (Visual Basic)
ReDim 陳述式 (Visual Basic)