What are the different types of arrays in QTP?

Two types of arrays in QTP, they are

Static and dynamic array

Static arrays cannot be resized during run time

Dynamic arrays can be resized during run time

Static Array with an example

Syntax:

variablename =array(values)

myarray =array(10,20,30)

myarray is a variable name which stores the values of  an array

array() -Keyword to define array

10,20,30 -Values inside the array

msgbox myarray(2)

Execute the above code, output will be shown as 30, how because

Myarray(0) =10

Myarray(1) =20

Myarray(2) =30

In Msgbox specified as myarray(2), so output is 30

How to find out lowest value of an array

By default lowest value of an array is “0”

or use Lbound  to find out lowest value of an array

arraycount =Lbound(myarray)

msgbox arraycount

Output will be shown as “0”

 How to find out highest value of an array

Highest value of an array is depends on the value stored inside the array

or use Ubound to find out highest value of an array

 arraycount =Ubound(myarray)

msgbox arraycount

In the above example it shows an output as 2(Highest value of an array)

Dynamic Array With an example

It will resize during run time

Syntax:

ReDim Array(Arraysize)

ReDim  Preserve Array(Arraysize)

Example:

ReDim  myarray(2)

myarray(0) =”1″

myarray(1) =”2″

myarray(2) =”3″

ReDim  Preserve myarray(3)

myarray(3)=”4″

msgbox myarray(0) & myarray(1) &myarray(2) &myarray(3)

 

In First line keeping in mind  and declaring array as dynamic array(Re Dim), Initially array size was 2 but later need to increase the size of array, so increasing the array size by declaring ReDim  Preserve keyword

Preserve is used to keep already executed data.

With use of Preserve keyword you can get the output of “1234”

Without use of preserve keyword you will get only “4”

How to use Array with input box:

Example

input =inputbox(“Enter your full name”)

mysplit =split(input,” “)

may= mysplit(1)

msgbox may

In the above example Enter your full name with spaces, example, Info Yep(with spaces), in the above example delimiter  used as Space(“ “), and printing the name which was separated by spaces.

Example output is “Yep”

arrays output
arrays output in a msgbox

Array size can be increased or decreased based on input data

2 thoughts on “What are the different types of arrays in QTP?”

Leave a Reply

Your email address will not be published. Required fields are marked *