QTP VB Script
QTP VB Script
Definition
Operators
Functions
Statements
Definition
What is a scripting language?
What is VBScript?
Arithmetic Operators
- Operators used to perform mathematical calculations
results in a number.
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.
Concatenation Operators
- Operators used to combine strings.
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]]])
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
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
? Or !
Thank You