**VBScript Tutorials - Herong's Tutorial Examples** - Version 5.23, by Dr. Herong Yang

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:

- Addition (+): Returns the mathematical sum of both operands.
- Subtraction (-): Returns the result of the first operand subtracted by the second operand.
- Unary Negation (-): Returns the negative value of the only operand.
- Multiplication (*): Returns the result of the first operand multiplied by the second operand.
- Division (/): Returns the result of the first divided by the second operand.
- Integer Division (\): Returns the result of the first operand divided by the second operand. Both operands are rounded to integer values before the operation. The decimal fraction part is removed from the resulting value.
- Modulus (also called Remainder) (Mod): Returns the remainder of the first operand divided by the second operand. Both operands are rounded to integer values before the operation.
- Exponentiation (^): Returns the first operand raised to the power of the second operand.

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

<html> <body> <!-- arithmetic_operation.html - Copyright (c) 2015, 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

Introduction of VBScript - Visual Basic Scripting Edition

Variant Data Type, Subtypes, and Literals

►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

Inspecting Variables Received in Procedures

Error Handling Flag and the "Err" Object

Regular Expression Pattern Match and Replacement

scrrun.dll - Scripting Runtime DLL Library

IE Web Browser Supporting VBScript