Arithmetic Operators in VBScript



Following table shows all the arithmetic operators supported by VBScript language. Assume variable A holds 5 and variable B holds 10, then −

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

Example

Try the following example to understand all the arithmetic operators available in 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>

When you save it as .html and execute it in Internet Explorer, then the above script will produce the following result −

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
Advertisements