Thursday, May 21, 2009

Dynamic arrays in QTP?

You can use the Dim statement to declare an array with empty parentheses to declare a dynamic array. You use the Preserve keyword to preserve the data in an existing array when you change the size of the last dimension

Dim a() ' Allocates nothing.we can't declare array as a(2) and resize it to a(4)
ReDim preserve a(0)
a(0) = 0
ReDim preserve a(1)
a(1) = 1
ReDim preserve a(2)
a(2) = 2
ReDim preserve a(3)
a(3) = 3
ReDim preserve a(4) ' to preserve the contents of the array as the resizing takes place.
a(4)= 4
For each ite in a
msgbox ite ' o/p : 0 1 2 3 4

No comments:

Post a Comment