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

"*" - Arithmetic Multiplication Operation

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

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

- Arithmetic multiplication operation uses the multiplication operator: "*"
- Arithmetic multiplication 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.
- The Boolean subtype is considered as a numeric subtype in a multiplication 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 a multiplication operation. "Empty" represents a numeric value of 0.
- When a String value is used in a multiplication operation, it will be parsed into a Double value. If the parsing process fails, the multiplication operation will raise the "Type mismatch" runtime error.
- The returning value is the result of the first operand multiplied by the second operand.
- The subtype of the returning value is determined by the returning value range and subtypes of operands.

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

<html> <body> <!-- multiplication_operation.html - Copyright (c) 2015, HerongYang.com, All Rights Reserved. --> <pre> <script language="vbscript"> document.writeln("3*7=" & (3*7) & " : " & TypeName(3*7)) document.writeln("3*777777=" & (3*777777) & " : " _ & TypeName(3*777777)) document.writeln("3*9.99=" & (3*9.99) & " : " & TypeName(3*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("True*False=" & (True*False) & " : " _ & TypeName(True*False)) document.writeln("3*Empty=" & (3*Empty) & " : " _ & TypeName(3*Empty)) </script> </pre> </body> </html>

Here is the output of this VBScript example script:

3*7=21 : Integer 3*777777=2333331 : Long 3*9.99=29.97 : Double 3*333.333e200=9.99999E+202 : Double 3*"7"=21 : Double 3*True=-3 : Integer 3*False=0 : Integer True*False=0 : Integer 3*Empty=0 : Integer

The output confirms some of arithmetic multiplication operation rules:

- "3*7=21 : Integer" shows that the result is an Integer value, because the result is small value and both operands are Integer values.
- "3*777777=2333331 : Long" shows that the result is a Long value, because the result is large value outside the Integer value range.
- "3*9.99=29.97 : Double" shows that the result is a Double value, because the second operand is a Double value. "9.99" is a Double literal. See the data literal section in the previous chapter.
- "3*"7"=21 : Double" shows that the result is a Double value, because the second operand is a Double value. When a string is parsed into a numeric value, it returns a Double value.
- The statement on (7*"7Hello") is commented out, because string "7Hello" can not parsed into a Double value.
- "True*False=0 : Integer" shows that VBScript recognizes True as -1 and False as 0.

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