当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


VBScript UBound用法及代码示例



UBound 函数返回指定数组的最大下标。因此,该值对应于数组的大小。

用法

UBound(ArrayName[,dimension])
  • ArrayName, 必需参数。此参数对应于数组的名称。

  • dimension,一个可选参数。这需要一个与数组维度相对应的整数值。如果是'1',则返回第一维的下界;如果是'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

相关用法


注:本文由纯净天空筛选整理自 VBScript UBound Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。