### VBScript Operators

VBScript Operators

Operators are used to perform Mathematical, Comparison and Logical operations.

Operator precedence (Operator evaluation priority process)

Generally VBScript evaluates Operators from left to right, if any high priority operator is there in right side then VBScript evaluates high priority operator first.

Example:Msgbox 10 + 4 * 3 '22

In order to Override Operator precedence we can use ()

Example:Msgbox (10 + 4) * 3 '42
------------------------------
Three Categories of Operators in VBScript

i) Arithmetic Operators

ii) Comparison Operators

iii) Logical Operators
----------------------
Concatenation Operators (* part of Arithmetic Operators)
------------------------------------------
i) Arithmetic Operators
a) Exponentiation ^

b) Multiplication *

c) Division /

d) Integer Division \

e) Mod

g) Subtraction -

h) Concatenation &
--------------------------------
Example:
Dim a, b
a = 10
b = 3

Msgbox a ^ b '1000

Msgbox a * b '30

Msgbox a / b '3.333333333

Msgbox a \ b '3

Msgbox a Mod b '1

Msgbox a + b '13

Msgbox a - b '7

Msgbox a & b '103
-------------------
+ Operator
& Operator
----------------
+ Operator

Dim a, b
a = 10
b = 3

Msgbox a + b '13

a = "10"
b = 3
Msgbox a + b '13

a = "10"
b = "3"
Msgbox a + b '103

a = "Hydera"

b = "123"

b = 123
Msgbox a + b 'Incorrect usage
---------------------------------
& Operator

Dim a, b
a = 10
b = 3

Msgbox a & b '103

a = "10"
b = 3
Msgbox a & b '103

a = "10"
b = "3"
Msgbox a & b '103

a = "Hydera"

b = "123"

b = 123
--------------------------------------
ii) Comparison Operators (All operators are equal)

a) =

b) <>

c) >

d) >=

e) <

f) <=
------------------------------------
Note: Comparison Operators return Boolean (True/False) result.

Example:
Dim a, b
a = 10
b = 3

Msgbox a = b 'False

Msgbox a < b 'False

Msgbox a <= b 'False

Msgbox a <> b 'True

Msgbox a > b 'True

Msgbox a >= b 'True
------------------------------------------------
iii) Logical Operators
a) Not (Logical Negation)

Example:

SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
End If

b) And (Logical Conjunction)

Result Criteria:

Exp1    Exp2    Result
------------------------
True    True    True
True    False    False
False    True    False
False    False    False

Example:

Dim a, b, c
a = 100
b = 70
c = 50

If a > b And a > c Then
Msgbox "A is a Big Number"
Else
Msgbox "A is not a Big Number"
End If
------------------------------
c) Or (Logical Disjunction)

Exp1    Exp2    Result
------------------------
True    True    True
True    False    True
False    True    True
False    False    False

d) Xor (Logical Exclusion)
----------------------------
Exp1    Exp2    Result
------------------------
True    True    False
True    False    True
False    True    True
False    False    False
------------------------------------------