Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use an Array in an Action declared in another Action
#1
Solved: 11 Years, 3 Months, 2 Weeks ago
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.
Reply
#2
Solved: 11 Years, 3 Months, 2 Weeks ago
You can use the array concept in the function. And wherever necessary call the function which will return the array value.
Reply
#3
Solved: 11 Years, 3 Months, 2 Weeks ago
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....
Reply
#4
Solved: 11 Years, 3 Months, 2 Weeks ago
Pass it as an parameter with a different name and see what happens.
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Reply
#5
Solved: 11 Years, 3 Months, 2 Weeks ago
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
Reply
#6
Solved: 11 Years, 3 Months, 2 Weeks ago
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Action Parameterization Issue Slothman 1 1,942 10-31-2020, 01:05 PM
Last Post: Ankur
  no action on click for particular wpf button jlavrecka 1 1,396 05-21-2020, 11:33 PM
Last Post: jlavrecka
  Object not found during the 2nd iteration of an Action call in a For loop BGunay 0 959 04-23-2020, 07:08 PM
Last Post: BGunay
  UFT 14.01 - identifying wpf objects. but not performing action. chinmoyee 1 2,474 11-15-2017, 03:42 PM
Last Post: Ankur
  Default state of new action aparajita 1 2,328 08-25-2015, 12:11 AM
Last Post: aparajita

Forum Jump:


Users browsing this thread: 1 Guest(s)