QTP Training
QTP Training
Visit:
Visit:
www.gcreddy.com
www.gcreddy.com
for QTP and VB script Information
for QTP and VB script Information
VB Script Functions with Examples
VB Script Functions with Examples
Abs Function
Abs Function
It returns obsolete value of the given number. It returns obsolete value of the given number.
Dim num Dim num num=157.56 num=157.56 num=Abs(num) num=Abs(num)
msgbox num 'Output:
msgbox num 'Output: 157.56157.56 num=-157.56
num=-157.56 num=Abs(num) num=Abs(num)
msgbox num 'Output:
msgbox num 'Output: 157.56157.56 Note: It provide positive value Note: It provide positive value Array Function
Array Function
We can enter list of values using
We can enter list of values using this functionthis function Ex: Ex: Dim var Dim var 'List of strings 'List of strings
gcreddy.com
gcreddy.com
11QTP Training
QTP Training
var=Array("Hyderabad","Che
var=Array("Hyderabad","Chennai", nnai", "Nellore")"Nellore") msgbox var(0) 'output: Hyderabad
msgbox var(0) 'output: Hyderabad msgbox var(1) 'output: Chennai msgbox var(1) 'output: Chennai msgbox var(2) 'output: Nellore msgbox var(2) 'output: Nellore 'List of numeric values
'List of numeric values var=Array(100
var=Array(100,200, ,200, 300)300) msgbox var(0) 'output: 100 msgbox var(0) 'output: 100 msgbox var(1) 'output: 200 msgbox var(1) 'output: 200 msgbox var(2) 'output: 300 msgbox var(2) 'output: 300 'List of mixed values
'List of mixed values var=Array(100
var=Array(100,"India", ,"India", #01-05-201#01-05-2010#)0#) msgbox var(0) 'output: 100
msgbox var(0) 'output: 100 msgbox var(1) 'output: India msgbox var(1) 'output: India msgbox var(2) 'output:
msgbox var(2) 'output: 01/05/20101/05/20100 IsArray Function
IsArray Function
It checks weather the given variable is an
It checks weather the given variable is an Array or notArray or not Dim var1, var2,x
Dim var1, var2,x 'List of strings 'List of strings var1=Array("Hy
var1=Array("Hyderabad","Chennai", derabad","Chennai", "Nellore")"Nellore") x=isArray(var1) 'It returns True/False like Result x=isArray(var1) 'It returns True/False like Result msgbox x msgbox x x=isArray(var2) x=isArray(var2) msgbox x msgbox x IsDate IsDate
It checks weather the given value is Date type data
It checks weather the given value is Date type data or notor not Examples: Examples: Dim myDate,x Dim myDate,x myDate=100 myDate=100 x=IsDate(myDate) x=IsDate(myDate)
msgbox x 'Output: False msgbox x 'Output: False myDate="India" myDate="India" x=IsDate(myDate) x=IsDate(myDate)
gcreddy.com
gcreddy.com
22QTP Training
QTP Training
msgbox x 'Output: False msgbox x 'Output: False myDate=#10/05/2010# myDate=#10/05/2010# x=IsDate(myDate)
x=IsDate(myDate)
msgbox x 'Output: True msgbox x 'Output: True myDate=#10-05-2010# myDate=#10-05-2010# x=IsDate(myDate)
x=IsDate(myDate)
msgbox x 'Output: True msgbox x 'Output: True myDate=#10-05-10# myDate=#10-05-10# x=IsDate(myDate) x=IsDate(myDate)
msgbox x 'Output: True msgbox x 'Output: True myDate=10-05-2010 myDate=10-05-2010 x=IsDate(myDate) x=IsDate(myDate)
msgbox x 'Output: False msgbox x 'Output: False DateDiff Function
DateDiff Function
It provides difference between two dates, based on interval It provides difference between two dates, based on interval (day/month)
(day/month)
Dim Date1, Date2,x Dim Date1, Date2,x Date1=#10-10-2008# Date1=#10-10-2008# Date2=#10-09-2010# Date2=#10-09-2010#
x=DateDiff("d", date1,date2) 'd for day x=DateDiff("d", date1,date2) 'd for day msgbox x' It subtracts date1 from date2 msgbox x' It subtracts date1 from date2 x=DateDiff("m", date1,date2)' m for month x=DateDiff("m", date1,date2)' m for month msgbox x' It subtracts date1 from date2 msgbox x' It subtracts date1 from date2
x=DateDiff("y", date1,date2) 'it considers days only x=DateDiff("y", date1,date2) 'it considers days only msgbox x' It subtracts date1 from date2
msgbox x' It subtracts date1 from date2
Note: through this function, we can day or month wise diffrence only. Note: through this function, we can day or month wise diffrence only. IsNumeric
IsNumeric
It checks weather the given value is numeric or not and
It checks weather the given value is numeric or not and It providesIt provides True/False like Result
True/False like Result
gcreddy.com
QTP Training
QTP Training
Example: Example: Dim val,x Dim val,x val="100" val="100" x=Isnumeric(val) x=Isnumeric(val)msgbox x 'Output: True msgbox x 'Output: True val=100
val=100
x=Isnumeric(val) x=Isnumeric(val)
msgbox x 'Output: True msgbox x 'Output: True x=Isnumeric(500)
x=Isnumeric(500)
msgbox x 'Output: True msgbox x 'Output: True x=Isnumeric("India") x=Isnumeric("India") msgbox x 'Output: False msgbox x 'Output: False Len Function
Len Function
It finds length of the String It finds length of the String Example: Example: Dim val,x Dim val,x val="Hyderabad" val="Hyderabad" x=Len(val) x=Len(val) msgbox x 'Output: 9 msgbox x 'Output: 9 val=100 val=100 x=Len(val) x=Len(val) msgbox x 'Output: 3 msgbox x 'Output: 3 val="Hydera100" val="Hydera100" x=Len(val) x=Len(val) msgbox x 'Output: 9 msgbox x 'Output: 9 val="hy$@*de" val="hy$@*de" x=Len(val) x=Len(val) msgbox x 'Output: 7 msgbox x 'Output: 7 val="100" val="100" x=Len(val) x=Len(val)
gcreddy.com
gcreddy.com
44QTP Training
QTP Training
msgbox x 'Output: 3 msgbox x 'Output: 3 val=#10-10-2010# val=#10-10-2010# x=Len(val) x=Len(val) msgbox x 'Output: 10 msgbox x 'Output: 10 x=Len("Krishna") x=Len("Krishna") msgbox x 'Output: 7 msgbox x 'Output: 7 x=Len(Krishna) x=Len(Krishna) msgbox x 'Output: 0 msgbox x 'Output: 0 x=Len() x=Len()msgbox x 'Output: Error msgbox x 'Output: Error
Left Function
Left Function
Returns a specified number of charectors of a
Returns a specified number of charectors of a given string from leftgiven string from left side side Syntax: Syntax: variable=Left(string,Lengh) variable=Left(string,Lengh) Example: Example: Dim val,x Dim val,x val="Hyderabad" val="Hyderabad" x=Left(val,3) x=Left(val,3)
msgbox x ' Output: Hyd msgbox x ' Output: Hyd
val="9247837478" val="9247837478" x=Left(val,1) x=Left(val,1) msgbox x ' Output: 9 msgbox x ' Output: 9 val="H92yderabad" val="H92yderabad" x=Left(val,3) x=Left(val,3) msgbox x ' Output: H92 msgbox x ' Output: H92 x=Left(9247837478,5) x=Left(9247837478,5)
gcreddy.com
gcreddy.com
55QTP Training
QTP Training
msgbox x ' Output: msgbox x ' Output: 9247892478 val=#10-10-10# val=#10-10-10# x=Left(val,3) x=Left(val,3) msgbox x ' Output: 10/ msgbox x ' Output: 10/ Right Function Right FunctionReturns a specified number of characters of a
Returns a specified number of characters of a given string from Rightgiven string from Right side side Example: Example: Dim val,x Dim val,x val="Hyderabad" val="Hyderabad" x=Right(val,3) x=Right(val,3)
msgbox x ' Output: bad msgbox x ' Output: bad
val="9247837478" val="9247837478" x=Right(val,1) x=Right(val,1) msgbox x ' Output: 8 msgbox x ' Output: 8 val="H92yderabad" val="H92yderabad" x=Right(val,3) x=Right(val,3)
msgbox x ' Output: bad msgbox x ' Output: bad
x=Right(9247837478,5) x=Right(9247837478,5) msgbox x ' Output: msgbox x ' Output: 3747837478 val=#10-10-10# val=#10-10-10# x=Right(val,5) x=Right(val,5) msgbox x ' Output: msgbox x ' Output: /2010/2010 Mid function Mid function
Returns a specified number of characters of a
Returns a specified number of characters of a given stringgiven string Example: Example: Dim val,x Dim val,x
gcreddy.com
gcreddy.com
66QTP Training
QTP Training
val="Hyderabad" val="Hyderabad" x=Mid(Val,5,3) x=Mid(Val,5,3)msgbox x ' Output: rab msgbox x ' Output: rab val="Hyderabad"
val="Hyderabad" x=Mid(Val,5) x=Mid(Val,5)
msgbox x ' Output: rabad msgbox x ' Output: rabad val="9247837478" val="9247837478" x=Mid(val,6,5) x=Mid(val,6,5) msgbox x ' Output: msgbox x ' Output: 3747837478 val="H92yderabad" val="H92yderabad" x=Mid(val,1) x=Mid(val,1) msgbox x ' Output:
msgbox x ' Output: H92yderabadH92yderabad
x=Mid(9247837478,5) x=Mid(9247837478,5) msgbox x ' Output: msgbox x ' Output: 837478837478 val=#10-10-10# val=#10-10-10# x=Mid(val,5) x=Mid(val,5) msgbox x ' Output: msgbox x ' Output: 0/20100/2010 StrReverse StrReverse
Retunes reverse value of a string Retunes reverse value of a string Example: Example: Dim val,x Dim val,x val="Hyderabad" val="Hyderabad" x=StrReverse(val) x=StrReverse(val)
msgbox x 'Output dabaredyH msgbox x 'Output dabaredyH val="001" val="001" x=StrReverse(val) x=StrReverse(val) msgbox x 'Output: 100 msgbox x 'Output: 100 val=1002 val=1002 x=StrReverse(val) x=StrReverse(val) msgbox x 'Output: 2001 msgbox x 'Output: 2001
gcreddy.com
gcreddy.com
77QTP Training
QTP Training
val=#10-10-10# val=#10-10-10# x=StrReverse(val) x=StrReverse(val) msgbox x 'Output: msgbox x 'Output: 0102/010102/01/01/01 x=StrReverse("Hyderabad") x=StrReverse("Hyderabad") msgbox x 'Output: dabaredyH msgbox x 'Output: dabaredyH x=StrReverse(100) x=StrReverse(100) msgbox x 'Output: 001 msgbox x 'Output: 001 StrComp Function StrComp FunctionIt compares two string (Binary and textual) It compares two string (Binary and textual) if
if
a) Both are equal, returns 0(zero) a) Both are equal, returns 0(zero)
b) String 1 greater than string 2, returns 1(one) b) String 1 greater than string 2, returns 1(one) b) String 2 greater than string 1, returns -1
b) String 2 greater than string 1, returns -1
Example: Example: Dim str1,str2,x Dim str1,str2,x str1="India" str1="India" str2="India" str2="India" x=StrComp(str1,str2,1) x=StrComp(str1,str2,1) msgbox x 'Output 0 msgbox x 'Output 0 str1="india" str1="india" str2="INDIA" str2="INDIA" x=StrComp(str1,str2,1) x=StrComp(str1,str2,1) msgbox x 'Output 0 msgbox x 'Output 0 str1="India" str1="India" str2="Indian" str2="Indian" x=StrComp(str1,str2,1) x=StrComp(str1,str2,1) msgbox x 'Output -1 msgbox x 'Output -1 str1="Indian" str1="Indian" str2="Ndia" str2="Ndia" x=StrComp(str1,str2,1) x=StrComp(str1,str2,1)
gcreddy.com
gcreddy.com
88QTP Training
QTP Training
msgbox x 'Output -1 msgbox x 'Output -1 str1="Indian" str1="Indian" str2="India" str2="India" x=StrComp(str1,str2,1) x=StrComp(str1,str2,1) msgbox x 'Output 1 msgbox x 'Output 1 str1=100 str1=100 str2=100 str2=100 x=StrComp(str1,str2,1) x=StrComp(str1,str2,1) msgbox x 'Output 0 msgbox x 'Output 0 str1=100 str1=100 str2=101 str2=101 x=StrComp(str1,str2,1) x=StrComp(str1,str2,1) msgbox x 'Output -1 msgbox x 'Output -1 Lcase function Lcase functionCoverts Upper case values into Lower case Coverts Upper case values into Lower case Dim val,x Dim val,x val="HYDERABAD" val="HYDERABAD" x=Lcase(val) x=Lcase(val)
msgbox x 'Output hyderabad msgbox x 'Output hyderabad val="Hyderabad"
val="Hyderabad" x=Lcase(val) x=Lcase(val)
msgbox x 'Output hyderabad msgbox x 'Output hyderabad val="HederabaD"
val="HederabaD" x=Lcase(val) x=Lcase(val)
msgbox x 'Output hyderabad msgbox x 'Output hyderabad val="hyderabad"
val="hyderabad" x=Lcase(val) x=Lcase(val)
msgbox x 'Output hyderabad msgbox x 'Output hyderabad x=Lcase("HYDERABAD") x=Lcase("HYDERABAD") msgbox x 'Output hyderabad msgbox x 'Output hyderabad
gcreddy.com
QTP Training
QTP Training
Ucase function
Ucase function
Coverts Lower case values into Upper case Coverts Lower case values into Upper case Example: Example: Dim val,x Dim val,x val="HYDERABAD" val="HYDERABAD" x=Ucase(val) x=Ucase(val) msgbox x 'Output
msgbox x 'Output HYDERABADHYDERABAD val="Hyderabad"
val="Hyderabad" x=Ucase(val) x=Ucase(val)
msgbox x 'Output
msgbox x 'Output HYDERABADHYDERABAD val="HederabaD"
val="HederabaD" x=Ucase(val) x=Ucase(val)
msgbox x 'Output
msgbox x 'Output HYDERABADHYDERABAD val="hyderabad"
val="hyderabad" x=Ucase(val) x=Ucase(val)
msgbox x 'Output
msgbox x 'Output HYDERABADHYDERABAD x=Ucase("HYDERABAD")
x=Ucase("HYDERABAD") msgbox x 'Output
msgbox x 'Output HYDERABADHYDERABAD