# UFT Class 24

# UFT Class 24

### I) VBScript Operators

#### a) Arithmetic Operators:

Arithmetic Operators return value based result.

—————————

1) Exponentiation ^

2) Multiplication *

3) Division /

4) Integer Division \

5) Modules mod

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.33333333

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 = “Hyderabad”

b = “123”

c = a + b

Msgbox c ‘Hyderabad123

a = “Hyderabad”

b = “ABC”

c = a + b

Msgbox c ‘HyderabadABC

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 = “Hyderabad”

b = “123”

c = a & b

Msgbox c ‘Hyderabad123

a = “Hyderabad”

b = “ABC”

c = a & b

Msgbox c ‘HyderabadABC

a = “Hyderabad”

b = 123

c = a & b

Msgbox c ‘Hyderabad123

#### b) Comparison Operators (All are equal)

Comparison Operators return Boolean /logical (True or false) result.

1) =

2) <>

3) >

4) >=

5) <

6) <=

——————————-

**Example:**

Dim a, b, c

a =10

b =20

c = a = b

Msgbox c ‘False

c = a > b

Msgbox c ‘False

c = a >= b

Msgbox c ‘False

c = a <> b

Msgbox c ‘True

c = a < b

Msgbox c ‘True

c = a <= b

Msgbox c ‘True

#### c) Logical Operators

#### 1) Not (Logical Negation)

**Ex:**

If Not Dialog(“Login”).Exist(3) Then

SystemUtil.Run “C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe”

End If

Dialog(“Login”).Activate

Dialog(“Login”).WinEdit(“Agent Name:”).Set “asdf”

Dialog(“Login”).WinEdit(“Password:”).SetSecure “550787eda3b6ae2fc461b592b3778ebdc819e846”

Dialog(“Login”).WinButton(“OK”).Click

#### 2) And (Logical conjunction)

**Example:**

Dim a, b, c

a = 100

b= 50

c =70

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 for And Operator:**

————-

Exp1 Exp2 Result

————————

True True True

True False False

False True False

False False False

#### 3) Or (Logical Disjunction)

Result Criteria for Or Operator:

————-

Exp1 Exp2 Result

————————

True True True

True False True

False True True

False False False

#### 4) Xor (Logical exclusion)

Result Criteria for Xor Operator:

————-

Exp1 Exp2 Result

————————

True True False

True False True

False True True

False False False

————————

VBScript Flow Control Statements

Conditional Statements

Loop Statements

### II) VBScript Conditional Statements

> There are two types of Statements in VBScript

1) If statement

2) Select Case Statement

> Usage of conditional statements in UFT

1) To insert verification points

2) For Error handling

#### > Types of Conditions

1) Single Condition (Positive / Negative Conditions)

Ex:

If a = b Then -Positive condition

If Not (a = b) Then -Negative condition

Or

If a <> b Then

——————–

2) Compound Condition (Positive / Negative Conditions)

If a > b And a > c Then

3) Nested Condition (Positive / Negative Conditions)

If a > b Then

If a > c Then

If a > d Then

.

.

———————————–

> Usage of Conditional statements

#### 1) Execute a Statement when condition is True/ Simple if

**Syntax:**

If Condition Then Statement

**Example 1:**

Dim myDate

myDate = #10/10/2014#

If myDate < Date Then myDate = Date

Msgbox myDate

**Example 2:**

Dim myDate

myDate = #10/10/2016#

If myDate < Date Then myDate = Date

Msgbox myDate

#### 2) Execute a block of statements when condition is True.

**Syntax:**

If Condition Then

Statements

———–

———

End If

**Example:**

Dim a, b

a =100

b = 50

If a > b Then

Msgbox “A is a Big Number”

End If

#### 3) Execute a block of statements when condition is True, otherwise execute another block of statements.

**Syntax:**

If Condition Then

Statements

———–

———

Else

Statements

———

———–

End If

**Example:**

———

Dim a, b

a =100

b = 50

If a > b Then

Msgbox “A is a Big Number”

Else

Msgbox “B is a Big Number”

End If

————————

**Example 2:**

—————

Dim a, b

a = InputBox(“Enter A Value”)

b = InputBox(“Enter B Value”)

If Cint (a) > Cint (b) Then

Msgbox “A is a Big Number”

Else

Msgbox “B is a Big Number”

End If

—————–

**Example 3:**

—————

Dim a, b

a = InputBox(“Enter A Value”)

b = InputBox(“Enter B Value”)

If IsNumeric(a) = True And IsNumeric(b) = True Then

If Cint (a) > Cint (b) Then

Msgbox “A is a Big Number”

Else

Msgbox “B is a Big Number”

End If

Else

Msgbox “Invalid Input”

End If

———————————

4) Decide among several alternates (Elseif Structure)

5) Execute a block of statements when more than one condition is True (Nested if)

6) Decide among several alternates (Using select case structure)

(4)