Vbscript-arithmetic-operators

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

VBScriptの算術演算子

次の表は、VBScript言語でサポートされているすべての算術演算子を示しています。 変数Aが5を保持し、変数Bが10を保持すると仮定します-

Operator Description Example
+ Adds two operands A + B will give 15
- Subtracts second operand from the first A - B will give -5
* Multiply both operands A* B will give 50
/ Divide numerator by denumerator B/A will give 2
% Modulus Operator and remainder of after an integer division B MOD A will give 0
^ Exponentiation Operator B ^ A will give 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>

lとして保存して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