Information.UBound(Array, Int32) Método
Definição
Retorna o subscrito mais alto disponível para a dimensão indicada de uma matriz.Returns the highest available subscript for the indicated dimension of an array.
public static int UBound (Array Array, int Rank = 1);
static member UBound : Array * int -> int
Public Function UBound (Array As Array, Optional Rank As Integer = 1) As Integer
Parâmetros
- Array
- Array
Obrigatórios.Required. Matriz de qualquer tipo de dados.Array of any data type. A matriz na qual você deseja encontrar o subscrito mais alto possível de uma dimensão.The array in which you want to find the highest possible subscript of a dimension.
- Rank
- Int32
Opcional.Optional. Integer.Integer. A dimensão para a qual o subscrito mais alto possível deve ser retornado.The dimension for which the highest possible subscript is to be returned. Use 1 para a primeira dimensão, 2 para a segunda e assim por diante.Use 1 for the first dimension, 2 for the second, and so on. Se Rank for omitido, 1 será pressuposto.If Rank is omitted, 1 is assumed.
Retornos
Integer.Integer. O valor mais alto da subscrição que a dimensão especificada pode conter.The highest value the subscript for the specified dimension can contain. Se Array tiver apenas um elemento, UBound retornará 0.If Array has only one element, UBound returns 0. Se Array não tiver elementos (por exemplo, se for uma cadeia de tamanho zero), UBound retornará -1.If Array has no elements, for example if it is a zero-length string, UBound returns -1.
Exceções
Array é Nothing.Array is Nothing.
Rank é menor que 1 ou Rank é maior que a classificação de Array.Rank is less than 1, or Rank is greater than the rank of Array.
Exemplos
O exemplo a seguir usa a UBound função para determinar o maior subscrito disponível para a dimensão indicada de uma matriz.The following example uses the UBound function to determine the highest available subscript for the indicated dimension of an array.
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.
Comentários
Como os subscritos de matriz começam em 0, o comprimento de uma dimensão é maior por um do que o mais alto subscrito disponível para essa dimensão.Since array subscripts start at 0, the length of a dimension is greater by one than the highest available subscript for that dimension.
Para uma matriz com as seguintes dimensões, UBound retorna os valores na tabela a seguir:For an array with the following dimensions, UBound returns the values in the following table:
Dim a(100, 5, 4) As Byte
| Chamada para UBoundCall to UBound | Valor retornadoReturn value |
|---|---|
UBound(a, 1) |
100100 |
UBound(a, 2) |
55 |
UBound(a, 3) |
44 |
Você pode usar UBound para determinar o número total de elementos em uma matriz, mas deve ajustar o valor que ele retorna para considerar o fato de que os subscritos iniciam em 0.You can use UBound to determine the total number of elements in an array, but you must adjust the value it returns to account for the fact that the subscripts start at 0. O exemplo a seguir calcula o tamanho total da matriz a no exemplo anterior:The following example calculates the total size of the array a in the preceding example:
Dim total As Integer
total = (UBound(A, 1) + 1) * (UBound(A, 2) + 1) * (UBound(A, 3) + 1)
O valor calculado para total é 3030, que é 101 * 6 * 5.The value calculated for total is 3030, which is 101 * 6 * 5.