Fonction VBScript UBound

La fonction UBound renvoie le plus grand indice du tableau spécifié. Par conséquent, cette valeur correspond à la taille du tableau.

Syntaxe

UBound(ArrayName[,dimension])
  • ArrayName, un paramètre obligatoire. Ce paramètre correspond au nom du tableau.

  • dimension, un paramètre facultatif. Cela prend une valeur entière qui correspond à la dimension du tableau. S'il vaut «1», alors il renvoie la limite inférieure de la première dimension; s'il vaut «2», il renvoie la limite inférieure de la deuxième dimension, et ainsi de suite.

Exemple

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         Dim arr(5)
         arr(0) = "1"            'Number as String
         arr(1) = "VBScript"     'String
         arr(2) = 100            'Number
         arr(3) = 2.45           'Decimal Number
         arr(4) = #10/07/2013#   'Date
         arr(5) = #12.45 PM#     'Time

         document.write("The Largest Subscript value of  the given array is : " & UBound(arr))

         ' For MultiDimension Arrays :
         Dim arr2(3,2)
         document.write(
            "The Largest Subscript of the first dimension of arr2 is : " & UBound(arr2,1) & "<br />")
         document.write(
            "The Largest Subscript of the Second dimension of arr2 is : " & UBound(arr2,2) & "<br />")

      </script>
   </body>
</html>

Lorsque le code ci-dessus est enregistré au format .HTML et exécuté dans Internet Explorer, il produit le résultat suivant -

The Largest Subscript value of the given array is : 5
The Largest Subscript of the first dimension of arr2 is : 3
The Largest Subscript of the Second dimension of arr2 is : 2