Micro Focus QTP (UFT) Forums
Filling Arrays dyanmically - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Others (https://www.learnqtp.com/forums/Forum-UFT-QTP-Others)
+--- Thread: Filling Arrays dyanmically (/Thread-Filling-Arrays-dyanmically)



Filling Arrays dyanmically - srinivas - 08-13-2008

Hi Ankur , First let me thank u for maintaining such a helpful forum.
iam facing a problem with dynamic arrays
i wanna fill a array at run time
here ismy code


Code:
x=JavaWindow("Legal ").JavaList("Role(s)").GetROProperty("items count")

For i=0 to x-1
    rolei=javawindow("Legal ").JavaList("Role(s)").GetItem(i)
    msgbox i
[size=x-large]calypsoarray(i)=rolei[/size]
   msgbox rolei

Next

its giving me a type mismatch error


RE: Filling Arrays dyanmically - somisays - 08-14-2008

Dear Srinivas,

May i know why you are using x-1 ?

Use i = 0 to x and try...


RE: Filling Arrays dyanmically - Rekha - 08-14-2008

Dear Mr.Sridhar,

If 0 to x is taken, index will be beyond the range by 1 and may show an subscript error? is it not?

Rekha


RE: Filling Arrays dyanmically - somisays - 08-15-2008

Hi,
I think you forgot to declare array...

Dim calypsoarray(10)

You can choose the size depending upon the requirement..


RE: Filling Arrays dyanmically - srinivas - 08-15-2008

Hi i need an array dynamic , i dont want to mention the array size
array size should be dynamic by that i can fill the array with n number of elements

thanking you both rekha and somiyasis


Srinu


RE: Filling Arrays dyanmically - somisays - 08-15-2008

Dear Srinivas,

Please see the modified code using Dynamic Array...

Code:
Dim calypsoarray()

x=JavaWindow("Legal ").JavaList("Role(s)").GetROProperty("items count")

For i=0 to x-1
             Redim calypsoarray(x)
    rolei=javawindow("Legal ").JavaList("Role(s)").GetItem(i)
    msgbox i
[size=x-large]calypsoarray(i)=rolei[/size]
   msgbox rolei

Next

For Dynamic arrays you have to specify the size by using the Redim statement .


Hope this helps..


RE: Filling Arrays dyanmically - srinivas - 08-18-2008

Hi somisays

It worked ,the solution is cool

Thank u man