當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。