Micro Focus QTP (UFT) Forums
Array as an environment variable..... - 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: Array as an environment variable..... (/Thread-Array-as-an-environment-variable)



Array as an environment variable..... - rachna_nags - 04-07-2011

Hi All,

I am facing an issue in my script.Actually i have a function which is common in few scripts. In which i am assigning values in an array.
In a script the value of this array from this function has to be used in another funstion in the same script. But i am enable to implement this as this array becomes local to the function so it's value can not be used in another function.
That's why i want to make this array as a global array(variable).o that value from one function can be used in another function in same script.
And for this i am thiniking to make this array a an environment variable.
But i donn know how to make it as environment variable and then save any value in an envirionment array variable...

Please help me out to resolve this problem..

Thanks,




RE: Array as an environment variable..... - manishbhalshankar - 04-07-2011

Hi Rachna,

You can achieve this by returning array through your function.

Syntax:
function name = array

It can also be done using Dictionary object (Scripting.Dictionary).

Please let me know if you are not able to reach the solution.


RE: Array as an environment variable..... - kirk6acosta - 04-07-2011

What if the array is passed to the function as a parameter when it is called using call by value or call by reference?


RE: Array as an environment variable..... - basanth27 - 04-07-2011

Environment variable for a array is a ruled out option. Why are you not declaring it as a global variable?
Public TestArray(10)
??


RE: Array as an environment variable..... - rachna_nags - 04-08-2011

Thanks for reply. I have tried the same still if i'll use this array in function a message that 'Type mismatch ' is getting populated..Sad


RE: Array as an environment variable..... - anil2u - 11-01-2011

I used something like this in one of my code and it worked for me.

Code:
Dim avlprglist(4)
var=GetAvailProgram(searchText,avlprglist)
var=SelectProgram(avlprglist)
FunctionGetAvailProgram(searchText,avlprglist)
  ....code....
  avlprglist=assign the array I created here
End Function

This can also be obtained as a return value for function as some one suggested above like:
Code:
var=yourFunction()
x=newFunction(var)
Function yourFunction()
  --code---
  yourFunction=assign the array
End Function

Another thing is we have to define an array with range definitely before using it.

Hope this helps


RE: Array as an environment variable..... - ravi.gajul - 11-01-2011

Hi Rachna ,see if the below code helps.Its not throwing type Mismatch error
Code:
public Arr
arr=Mytest
msgbox Arr(0)
Call mytest1( arr)
' Function Defination
Public function Mytest()
  Mytest=Array(1,2,3,4)
End Function
Public function mytest1(Byref arr )
   msgbox arr(1)  
End Function
Regards,
Ravi


RE: Array as an environment variable..... - ssvali - 11-07-2013

Check the below link. It might be helpful.

http://www.advancedqtp.com/old_forums/viewtopic.php?t=1712