Vbscript-ubound-function

提供:Dev Guides
移動先:案内検索

VBScript UBound関数

UBound関数は、指定された配列の最大の添え字を返します。 したがって、この値は配列のサイズに対応します。

構文

UBound(ArrayName[,dimension])
  • ArrayName 、必須パラメーター。 このパラメーターは、配列の名前に対応しています。
  • dimension 、オプションのパラメーター。 これは、配列の次元に対応する整数値を取ります。 '1’の場合、最初の次元の下限を返します。 '2’の場合、2番目の次元の下限などを返します。

<!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>

上記のコードが.HTMLとして保存され、Internet Explorerで実行されると、次の結果が生成されます-

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