0% found this document useful (0 votes)
3 views19 pages

QTP VB Script

The document provides an overview of scripting languages, specifically focusing on VBScript, which is a subset of Visual Basic. It details various operators, functions, and statements used in VBScript, including arithmetic, comparison, logical, and string functions, as well as conditional and looping statements. Additionally, it outlines the syntax for creating custom functions and the structure of different types of statements.

Uploaded by

Sreekanth Payik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views19 pages

QTP VB Script

The document provides an overview of scripting languages, specifically focusing on VBScript, which is a subset of Visual Basic. It details various operators, functions, and statements used in VBScript, including arithmetic, comparison, logical, and string functions, as well as conditional and looping statements. Additionally, it outlines the syntax for creating custom functions and the structure of different types of statements.

Uploaded by

Sreekanth Payik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 19

Contents

 Definition

 Operators

 Functions

 Statements
Definition
What is a scripting language?

• A scripting language is a programming language that is interpreted rather than


compilation. It is lot more easy to learn, when compared to any programming
language like C.

What is VBScript?

• A subset of the Visual Basic Programming Language


• A programming language that does not follow some of the strict standards of some
other scripting languages (i.e. JavaScript is case sensitive, VBScript is not).
Operators

 Arithmetic Operators
- Operators used to perform mathematical calculations 
results in a number.

Ex: +, - , *, / (Floating Point), \ (Integer), ^ (Power)

 Comparison Operators
- Operators used to perform comparisons (compares like types of things) 
results in a Boolean value (true or false)

Ex: = (assign), <> (Not Equal), < (Less Than), > (Greater Than)
Operators
 Logical Operators
- Operators used to perform logical operations (combines Boolean values)

results in a Boolean value.

Ex: NOT (Logical Negation) – [ NOT 1 = 0 / NOT 0 = 1]


AND (Logical Conjunction) – [1 AND 1 =1 / 1 AND x = 0]
OR (Logical Disjunction) – [0 OR 0 = 0 / 1 OR x = 1]
XOR (Logical Exclusion) – [0 XOR 0 = 1 / 1 XOR x = 0]

 Concatenation Operators
- Operators used to combine strings.

Ex: & Operator, + Operator


Functions
 Date/Time Functions

 Conversion Function

 Math Functions

 Array Functions

 String Functions
Date/Time Functions
Date
Returns the current system date.

DateAdd
Returns a date to which a specified time interval has been added.
Syntax : DateAdd(interval,number,date)
Day
Returns a number between 1 and 31 that represents the day of the month.
Syntax : Day(date)

There are other similar functions also. Like Time, Hour, Minute
Conversion Function
Asc
Converts the first letter in a string to ANSI code, and returns the result.
Syntax : Asc(string)

CDate
Converts a valid date and time expression to the variant of subtype Date,
and returns the result.
Syntax : CDate(date)

Other conversion functions available are, chr, CInt, Clng, CStr, Hex, Oct.
Math Functions
Int
Returns the integer part of a specified number .
Syntax : Int(number)

Abs
Returns the absolute value of a specified number
Syntax : Abs(number)

Sin
Returns the sine of a specified number (angle).
Syntax : Sin(number)

Other math functions available are, Cos, Tan, Exp, Sqr, Sgn,
Array Functions
Array
Returns a variant containing an array .
Syntax : Array(arglist)

IsArray
Returns a Boolean value that indicates whether a specified variable is an
array. If the variable is an array, it returns True, otherwise, it returns False.
Syntax : IsArray(variable)

LBound
Returns the smallest subscript for the indicated dimension of an array.
Syntax : LBound(arrayname[,dimension])

Split
Returns a zero-based, one-dimensional array that contains a specified
number of substrings.
Syntax : Split(expression[,delimiter[,count[,compare]]])

Other array functions available are UBound, Filter, Join.


String Functions
String
Returns a string that contains a repeating character of a specified length.
Syntax : String(number,character)

StrComp
Compares two strings and returns a value that represents the result of the
comparison.
Syntax : StrComp(string1,string2[,compare])

StrReverse
Reverses a string .
Syntax : StrReverse(string)

Other string functions available are, Len, Trim, RTrim, Ltrim, Instr.
Custom Functions

• Syntax to create User Defined Functions

Function <FunctionName>
Statement 1
Statement 2
.
Statement n
Var1 = FunctionName
End Function
Statements

Conditional Statements

Looping Statements
Conditional Statements
Three Conditional Statements :

 If statement - use this statement if you want to execute a set of code when a
condition is true.
Syntax : If condition Then
statement1
statement2
End if

 If...Then...Else statement - use this statement if you want to select one of two
sets of lines to execute.
Syntax : If condition Then
statement
Else
statement
End If
Conditional Statements
 If...Then...ElseIf statement - use this statement if you want to select one of many
sets of lines to execute.
Syntax : If condition1 Then
statement
ElseIf condition2 Then
statement
Else
statement
End if

 select case statement - use this statement if you want to select one of many sets of
lines to execute
Syntax : Select Case <expression>
Case condition1
statements
Case condition2
statements
End Select
Looping Statements

Four Looping Statements :

 For...Next statement - runs statements a specified number of times.


Syntax: For counter = start to end [Step step]
statement
Next

 For Each...Next statement - runs statements for each item in a collection or


each element of an array
Syntax: For Each item In ItemList
statement
Next
Looping Statements
 Do...Loop statement - loops while or until a condition is true
Syntax: Do [{while}{until}condition]
statement
Loop

 While...Wend statement - Do not use it - use the Do...Loop statement instead


Syntax: While condition
statement
Wend
Questions and Answers

? Or !
Thank You

You might also like