site
stats
By Anish Pillai Anish Pillai Posted under qtp and vbscript tutorials | QTP Tutorials for Beginners

Part 2: QTP and VBScript | Operators in VBScript

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

In the previous article of this series we covered QTP VBScript basics and the VBScript variables. In this article, we’ll see the different types of operators in VBScript that you would be using frequently while working with QTP scripts. Operators in VBScript can be divided into four different types. These are –

a) Arithmetic Operators
b) Comparison Operators
c) Logical Operators
d) Concatenation Operator

VBScript Operators

VBScript Operators

Arithmetic Operators

These operators are used to perform mathematical operations. Lets see the different arithmetic operators we have in VBScript.

Operator What it Does Example
+ Addition of numbers 3+5 = 8
Subtraction of numbers 7-5 = 2
/ Finds the quotient when a number is divided by another 5/3 = 1, 9/3 = 3, 15/2 = 7
* Multiplication of numbers 2*5*3 = 30
^ Exponent. Computes the power. 2^3 = 8, 3^2 = 9
Mod Finds the remainder when a number is divided by another. 5 mod 3 = 2, 9 mod 5 = 4, 10 mod 5 = 0


Comparison Operators

Comparison operators are used to compare different numbers/strings and are mostly used in conditional statements such as If condition. Let’s see the different comparison operators available in VBScript.

Operator What it Does Example
= Checks if a number/string is equal to another 5=5 is True, “abc”=”def” is False
Checks if a number is greater than the other 10 > 5 is True
Checks if a number is less than the other 10 < 5 is False
>= Checks for greater than or equal to 5 >= 5 is True
<= Checks for less than or equal to 10 <= 10 is True
<>  Checks if a number or string is not equal to  another 10 <> 5 is True, “abc” <> “def” is True


Logical Operators

Logical operators help you deduce some result based on certain set of conditions. For example, if ‘today is holiday’ and ‘its not raining’ then ‘i will play outside’. Lets see the different logical operators that are available in VBScript.

Operator What it Does Example
And All conditions must be true for the output to hold. If var > 99 and var < 1000 then var is a three digit number.
Or Output holds if any of the conditions is true. If num = 50 or num = 100 then num is divisible by 10.
Not Inverts the result. If value is true, Not converts it to false. If value is false, Not converts it to true. tr = True
fl = False
msgbox NOT(tr) ‘will display False 
msgbox NOT(fl) ‘will display True


Concatenation Operator

Concatenation operator is used to concatenate or join strings. There is only one concatenation operator – & (ampersand). Lets see how it is used.

Operator What it Does Example
& Used to concatenate two or more strings. “auto” & “mat” & “ion” -> “automation”


This was all about the different types of operators available in VBScript. You can visit our QTP Tutorials link for more tutorials for QTP beginners.

If you enjoyed this article, you can join our blog to get free email updates directly in your inbox.

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×