"Mod" - Arithmetic Modulus Operation

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

Here are some detail rules about the arithmetic operation - modulus:

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

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

Here is the output of this VBScript example script:

21 Mod 7=0 : Integer
20.6 Mod 7=0 : Long
24 Mod 7=3 : Integer
24 Mod 6.6=3 : Long
24 Mod 6.4=0 : Long
3 Mod 777777=3 : Long
3 Mod 9.99=3 : Long
3.33 Mod 9.99=3 : Long
3 Mod "7"=3 : Long
3 Mod True=0 : Integer
False Mod True=0 : Integer
Empty Mod 3=0 : Integer

The output confirms some of arithmetic modulus operation rules:

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