- VBScript 教程
- VBScript - 主頁
- VBScript - 概覽
- VBScript - 語法
- VBScript - 啟用
- VBScript - 放置
- VBScript - 變數
- VBScript - 常量
- VBScript - 運算子
- VBScript - 決策
- VBScript - 迴圈
- VBScript - 事件
- VBScript - Cookie
- VBScript - 數字
- VBScript - 字串
- VBScript - 陣列
- VBScript - 日期
- VBScript 高階
- VBScript - 過程
- VBScript - 對話方塊
- VBScript - 面向物件
- VBScript - 正則表示式
- VBScript - 錯誤處理
- VBScript - 雜項語句
- VBScript 有用資源
- VBScript - 問題與解答
- VBScript - 快速指南
- VBScript - 有用資源
- VBScript - 討論
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
廣告