VBScript Operators

VBScript Operators, Arithmetic operators, Comparison or Relational Operators, Logical Operators, and Operator Precedence in VBScript.

Operators in VBScript

Operators are used to performing the mathematical, comparison, and logical operations.

Categories of operators:

1. Arithmetic Operators

2. Comparison Operators

3. Logical Operators

* Concatenation operators (Part of Arithmetic Operators)

Operator precedence:

Operator precedence is VBScript operator priority process,
Generally, VBScript evaluates operators from left to right, but if any high priority operator is there on the right side then first VBScript evaluates the high priority operator then the general rule.

Note: In order to override operator precedence, use () symbol

Example:

Msgbox 2 + 2 * 4 ^ 2 ’34
Msgbox (2 + 2) * 4 ^ 2 ’64
—————–
Msgbox 2 + 2 * 4 ’10
Msgbox (2 + 2) * 4 ’16


1. Arithmetic Operators

1) Exponentiation ^

2) Multiplication *

3) Division /

4) Integer Division \

5) Mod Operator

6) Addition +

7) Subtraction –

8) Concatenation &
———————————
Example:

Dim a, b, c
a = 10
b = 3
c = a ^ b
Msgbox c ‘1000

c = a * b
Msgbox c ’30

c = a / b
Msgbox c ‘3.33333333333

c = a \ b
Msgbox c ‘3

c = a Mod b
Msgbox c ‘1

c = a + b
Msgbox c ’13

c = a – b
Msgbox c ‘7

c = a & b
Msgbox c ‘103
——————————–
+ Operator
—————–
Dim a, b, c
a = 10
b = 3
c = a + b
Msgbox c ’13

a = 10
b = “3”
c = a + b
Msgbox c ’13

a = “10”
b = “3”
c = a + b
Msgbox c ‘103

a = “Hydera”
b = “bad”
c = a + b
Msgbox c ‘Hyderabad

a = “Hyderabad”
b = “123”
c = a + b
Msgbox c ‘Hyderabad123

a = “Hyderabad”
b = 123
c = a + b
Msgbox c ‘Error
————————————-
& Operator

Dim a, b, c
a = 10
b = 3
c = a & b
Msgbox c ‘103

a = 10
b = “3”
c = a & b
Msgbox c ‘103

a = “10”
b = “3”
c = a & b
Msgbox c ‘103

a = “Hydera”
b = “bad”
c = a & b
Msgbox c ‘Hyderabad

a = “Hyderabad”
b = “123”
c = a & b
Msgbox c ‘Hyderabad123

a = “Hyderabad”
b = 123
c = a & b
Msgbox c ‘Hyderabad123


2. Comparison Operators 

1) >

2) >=

3) <

4) <=

5) =

6) <>
————————–
Note: Comparison operators return Boolean (logical) results.
Ex: True / False
————————–
Example:

Dim a, b, c
a = 10
b = 3
c = a > b
Msgbox c ‘True

c = a >= b
Msgbox c ‘True

c = a <> b
Msgbox c ‘True

c = a < b
Msgbox c ‘False

c = a <= b
Msgbox c ‘False

c = a = b
Msgbox c ‘False


3. Logical Operators

1) Not (Logical Negation)

If Not Dialog(“Login”).Exist(3) Then
SystemUtil.Run “C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe”,””,”C:\Program Files\HP\Unified Functional Testing\samples\flight\app\”,””
End If
Dialog(“Login”).Activate @@ hightlight id_;_525276_;_script infofile_;_ZIP::ssf1.xml_;_
Dialog(“Login”).WinEdit(“Agent Name:”).Set “asdf” @@ hightlight id_;_66772_;_script infofile_;_ZIP::ssf2.xml_;_
Dialog(“Login”).WinEdit(“Password:”).SetSecure “555fe8c872cfa7718d3ea9b61ac921c85ea7371b” @@ hightlight id_;_66774_;_script infofile_;_ZIP::ssf3.xml_;_
Dialog(“Login”).WinButton(“OK”).Click @@ hightlight id_;_66776_;_script infofile_;_ZIP::ssf4.xml_;_
————————————–
2) And (Logical Conjunction)
Dim a, b, c
a = 100
b = 90
c = 80

If a > b And a > c Then
Msgbox “A is a Big Number”
Else
Msgbox “A is Not a Big Number”
End If
———————
Result Criteria:

Exp1 Exp2 Result
————————
True True True
True False False
False True False
False False False
——————————–
3) Or (Logical Disjunction)

Result Criteria:

Exp1 Exp2 Result
————————
True True True
True False True
False True True
False False False

4) XOr (Logical exclusion)

Result Criteria:

Exp1 Exp2 Result
————————
True True False
True False True
False True True
False False False

VBScript Tutorial

VBScript Videos

Follow me on social media:

1 thought on “VBScript Operators”

Leave a Comment