Introduction of Arithmetic Operations

This section provides a quick introduction of arithmetic operations supported by VBScript: addition, subtraction, multiplication, division, remainder, and exponentiation.

VBScript supports 8 arithmetic operations:

To show you some simple arithmetic operations, I wrote the following script, arithmetic_operation.html:

<html>
<body>
<!-- arithmetic_operation.html
 - Copyright (c) 1998 HerongYang.com. All Rights Reserved.
-->
<pre>
<script language="vbscript">
   document.writeln("1 + 1 = " & (1 + 1))
   document.writeln("0 - 3 = " & (0 - 3))
   document.writeln("- 3 = " & (- 3))
   document.writeln("9 * 9 = " & (9 * 9))
   document.writeln("20 / 3 = " & (20 / 3))
   document.writeln("20 \ 3 = " & (20 \ 3))
   document.writeln("20 Mod 3 = " & (20 Mod 3))
   document.writeln("3 ^ 4 = " & (3 ^ 4))
</script>
</pre>
</body>
</html>

Here is the output of this VBScript example script:

1 + 1 = 2
0 - 3 = -3
- 3 = -3
9 * 9 = 81
20 / 3 = 6.66666666666667
20 \ 3 = 6
20 Mod 3 = 2
3 ^ 4 = 81

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

Arithmetic Operations

Introduction of Arithmetic Operations

 "+" - Arithmetic Addition Operation

 "-" - Arithmetic Subtraction Operation

 "*" - Arithmetic Multiplication Operation

 "/" - Arithmetic Division Operation

 "\" - Arithmetic Integer Division Operation

 "Mod" - Arithmetic Modulus Operation

 "^" - Arithmetic Exponentiation Operation

 Numeric Comparison Operations and Logical Operations

 String Operations - Concatenation and Comparison

 Variable Declaration and Assignment Statement

 Expression and Order of Operation Precedence

 Statement Syntax and Statement Types

 Array Data Type and Related Statements

 Array References and Array Assignment Statements

 Conditional Statements - "If ... Then" and "Select Case"

 Loop Statements - "For", "While", and "Do"

 "Function" and "Sub" Procedures

 Built-in Functions

 Inspecting Variables Received in Procedures

 Error Handling Flag and the "Err" Object

 Regular Expression Pattern Match and Replacement

 scrrun.dll - Scripting Runtime DLL Library

 Creating Your Own Classes

 IE Web Browser Supporting VBScript

 IIS ASP Server Supporting VBScript

 WSH (Windows Script Host)

 References

 Full Version in PDF/EPUB