VBScript 中的算術運算子



下表列出了 VBScript 語言支援的所有算術運算子。假設變數 A 為 5,變數 B 為 10,那麼 −

運算子 描述 示例
+ 新增兩個運算元 A + B 將返回 15
- 從第一個運算元中減去第二個運算元 A - B 將返回 -5
* 兩個運算元相乘 A * B 將返回 50
/ 將分子除以分母 B / A 將返回 2
% 取模運算子,返回整數除法後的餘數 B MOD A 將返回 0
^ 指數運算子 B ^ A 將返回 100000

示例

嘗試以下示例來了解 VBScript 中的所有算術運算子 −

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         Dim a : a = 5
         Dim b : b = 10
         Dim c

         c = a+b
         Document.write ("Addition Result is " &c)
         Document.write ("<br></br>")    'Inserting a Line Break for readability
         
         c = a-b
         Document.write ("Subtraction Result is " &c)
         Document.write ("<br></br>")   'Inserting a Line Break for readability
         
         c = a*b
         Document.write ("Multiplication Result is " &c)
         Document.write ("<br></br>")
         
         c = b/a
         Document.write ("Division Result is " &c)
         Document.write ("<br></br>")
         
         c = b MOD a
         Document.write ("Modulus Result is " &c)
         Document.write ("<br></br>")
         
         c = b^a
         Document.write ("Exponentiation Result is " &c)
         Document.write ("<br></br>")
      </script>
   </body>
</html>

當您將其另存為 .html 格式並在 Internet Explorer 中執行時,上面的指令碼將產生以下結果 −

Addition Result is 15

Subtraction Result is -5

Multiplication Result is 50

Division Result is 2

Modulus Result is 0

Exponentiation Result is 100000
vbscript_operators.htm
廣告
© . All rights reserved.