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

"\" - Arithmetic Integer Division Operation

This section provides some detail rules and a tutorial example on how arithmetic integer division operation works in VBScript.

Here are some detail rules about the arithmetic operation - integer division:

- Arithmetic integer division operation uses the integer division operator: "\"
- Arithmetic integer division operation requires that at least one of the operands is a numeric subtype: Byte, Integer, Long, Single or Double.
- If an operand is not a numeric subtype, it will be converted into a numeric subtype.
- If an operand is not an integer, it will be rounded into an integer. If the rounding process fails, the whole operation will fail.
- The Boolean subtype is considered as a numeric subtype in an integer division operation. "True" represents a numeric value of -1. "False" represents a numeric value of 0.
- The Empty subtype is considered as a numeric subtype in an integer division operation. "Empty" represents a numeric value of 0.
- When a String value is used in an integer division operation, it will be parsed into a Long value. If the parsing process fails, the integer division operation will raise the "Type mismatch" runtime error.
- The operation will fail, if the second operand is a 0. Dividing by 0 is mathematically impossible.
- The returning value is the result of the first operand divided by the second operand with the decimal fraction part removed from the result.
- The subtype of the returning value is Integer or Long determined by the returning value range and subtypes of operands.

Here is a tutorial example showing you how arithmetic integer division operation rules work:

<html> <body> <!-- integer_division_operation.html - Copyright (c) 2015, HerongYang.com, All Rights Reserved. --> <pre> <script language="vbscript"> document.writeln("21\7=" & (21\7) & " : " & TypeName(21\7)) document.writeln("20.6\7=" & (20.6\7) & " : " & TypeName(20.6\7)) document.writeln("24\7=" & (24\7) & " : " & TypeName(24\7)) document.writeln("24\6.6=" & (24\6.6) & " : " & TypeName(24\6.6)) document.writeln("24\6.4=" & (24\6.4) & " : " & TypeName(24\6.4)) document.writeln("3\777777=" & (3\777777) & " : " _ & TypeName(3\777777)) document.writeln("3\9.99=" & (3\9.99) & " : " & TypeName(3\9.99)) document.writeln("3.33\9.99=" & (3.33\9.99) & " : " & TypeName(3.33\9.99)) ' document.writeln("3\333.333e200=" & (3\333.333e200) & " : " _ ' & TypeName(3\333.333e200)) document.writeln("3\""7""=" & (3\"7") & " : " & TypeName(3\"7")) ' document.writeln("3\""7Hello""=" & (3\"7Hello") & " : " _ ' & TypeName(3\"7Hello")) document.writeln("3\True=" & (3\True) & " : " & TypeName(3\True)) ' document.writeln("3\False=" & (3\False) & " : " _ ' & TypeName(3\False)) document.writeln("False\True=" & (False\True) & " : " _ & TypeName(False\True)) document.writeln("Empty\3=" & (Empty\3) & " : " _ & TypeName(Empty\3)) </script> </pre> </body> </html>

Here is the output of this VBScript example script:

21\7=3 : Integer 20.6\7=3 : Long 24\7=3 : Integer 24\6.6=3 : Long 24\6.4=4 : Long 3\777777=0 : Long 3\9.99=0 : Long 3.33\9.99=0 : Long 3\"7"=0 : Long 3\True=-3 : Integer False\True=0 : Double Empty\3=0 : Integer

The output confirms some of arithmetic integer division operation rules:

- Return values from all tests are Integer or Double values .
- "20.6\7=3 : Long" shows that the first operand is rounded up from 20.6 to 21.
- "24\6.6=3 : Long" shows that the second operand is rounded up from 6.6 to 7.
- "24\6.4=4 : Long" shows that the first operand is rounded down from 6.4 to 6.
- The statement on (3\333.333e200) is commented out, because the second operand could not be rounded to an integer - out of the Double value range.
- The statement on (3\False) is commented out, because dividing by 0 is not allowed.

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