Micro Focus QTP (UFT) Forums
How to use an Array in an Action declared in another Action - 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 Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to use an Array in an Action declared in another Action (/Thread-How-to-use-an-Array-in-an-Action-declared-in-another-Action)



How to use an Array in an Action declared in another Action - PrabhatN - 06-03-2010

Hi,

My need is as follows,

1. I have to declare an Array in an action (let say Action1) and put some data retrieved from an application in the array
2. I need the data stored in the array in another action (Action2)

Few things came into my mind but it was not done.They are as following,

1.Use of Environment Variable: But an Array cann't be added as an E.V
2.Use of Action Parameter: But an Array cann't be passed as an A.P

I then created a string using all the values of the array in Action1 and added the string as an Environment Variable and retrieve the string in Action2 and split it. In this way I got all the values from Action1 in Action2. But here the problem is when the array contains a large number of data the string is subsequently large enough to perform Split operation. It is not at all easier and convinient.

Anyone with any better idea? Please help me out.


RE: How to use an Array in an Action declared in another Action - guin.anirban - 06-03-2010

You can use the array concept in the function. And wherever necessary call the function which will return the array value.


RE: How to use an Array in an Action declared in another Action - PrabhatN - 06-07-2010

But how should be the structure of the function ?

In one action I need to pass the array as a parameter to the function. But in other actions I just need to get back the array.

So I cann't hav a function like:

Function getArray(ByRef arrayName)
-----Body-------
End Function

Because in Action1 it'll work fine coz I need to pass the array to the function here but in Action2 what should I pass?

Suggest....


RE: How to use an Array in an Action declared in another Action - basanth27 - 06-07-2010

Pass it as an parameter with a different name and see what happens.


RE: How to use an Array in an Action declared in another Action - sreekanth chilam - 06-07-2010

Hi Prabhat,

I would suggest you to go with "Dictionary Objects" to solve this requirement.

I had tried this on QTP 9.5V & its working fine for me.

Please follow the below steps:

In Action1:
Step1: Create the required array
Step2: Store all the Array values into Dictionary Object items(Variables)

In Action2:
Step3: Store all the Dictionary Items values into an Array variable
Step4: Loop thru the Array using Lbound,Ubound and access the array values in Action2

For more info. refer the code given below:

Code in Action1:
Code:
d=Array("London","Boston","Newyork","Sanfransisco")        
For i=0 to ubound(d)
   GlobalDictionary.Item("Name"&i)=d(i)            
Next

Code in Action2:
Code:
x=GlobalDictionary.items
   For j=0 to ubound(x)
     msgbox x(j)
  Next

Implement accordingly as per your requirement.

Hope this would solve your problem Smile


RE: How to use an Array in an Action declared in another Action - PrabhatN - 06-08-2010

Hello sreekanth,

Thanks for your valuable suggestion...

Actually I tried it with Dictionary Object but not the Global one Smile

Now it works fine and fulfilled the purpose.