Friday 15 August 2014

Array Functions in QTP


1)Array() in QTP


-> The Array function returns a  variant containing an array.

-> The first element of array index is zero.



Syntax

Array(arglist)


Here,

arglist - Required. Its contains value seperated by comma. and values represented as array.


Example:


a=array(3,5,8)
msgbox a(1)


Here the values are,

a(0)=3
a(1)=5
a(2)=8




2) Filter() in QTP

-> Filter function used to create another array variable from another array variable by using some filter creteria.


Syntex:

Filter(Source_arrayvariable,value[,include[,compare]])


Here,


Source_arrayvariable = Required. one dimensional array. This is source string

value = Required. Used for search string in Source_arrayvariable. Its case- sensitive.

include = Optional, Boolean value
 True = Default. Return String as per matched with above given value.
 False = Return string that is not matched as per above given value.
Compare = Optional. Specifies the string comparison to use.
0 = vbBinaryCompare - Perform a binary comparison
1 = vbTextCompare - Perform a textual comparison



Return Values:

Return new array with values from Source_arrayvariable as per the filter creteria.



Example:


a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=filter(A,"Sun",true)
For each str  In b
print str
Next



O/P
Sunday




3) IsArray() function in QTP

-> IsArray() returns boolean value and its indicates that given variable is array variable or normal variable.

->  If the variable is an array, it returns True, otherwise, it returns False.


Syntex :

IsArray(variable)

Variable : Required. Any variable


Return type:

True : If the variable is an array
False : If the variable is NOT an array,


Example:

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
print msgbox(IsArray(A))


O/P

TRUE



4) Join() funtion in QTP

The Join() function used to join all elements from array.


Syntex:

Join(Array_Variable[,delimiter])

Here,

Array_Variable = Required. one dimensional array variable name.
delimiter = optional, used to add delemiter char with end of all element(Sub String) in given array variable.


Return Types:

Its return String which contains all number of element (substrings) in an array.


Example :

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
print join(a,"#")

o/p

Sunday#Monday#Tuesday#Wednesday#Thursday#Friday#Saturday



5) Split Function in QTP


Split function used to zero based, one dimensional array that contains specified number of sub string.


Syntax:

Split(expression[,delimiter[,count[,compare]]])

Here,


6) LBound Function in QTP

Returns the smallest subscript for the indicated dimension of an array

LBound(arrayname[,dimension])





7) UBound Function in QTP

Returns the largest subscript for the indicated dimension of an array


UBound(arrayname[,dimension])

No comments:

Post a Comment