Micro Focus QTP (UFT) Forums
Global variables in QTP - 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: Global variables in QTP (/Thread-Global-variables-in-QTP)



Global variables in QTP - nidhishnair - 05-05-2011

Hi,

I would like to know how to declare and call the global variables in QTP, so that value from one action can be used in another.

I did a little bit of digging and came to know about environment variables. This is what i gave in one action whose value (my_no) had to be exported to the other action.

Code:
dim MyValue
Environment.Value("MyVariable")=my_no
MyValue=Environment.Value("MyVariable")

and in the other action i gave this:-

Code:
Dim no

no=Environment.Value("MyVariable")
msgbox(no)

Shld it not ideally display? Please tell me what went wrong..


RE: Global variables in QTP - supputuri - 05-05-2011

Hi,

You have couple of options here
1) Using environment variables
2) Using a global variable : You can create a variable in one of the library file (.vbs) and you can use that variable across all the actions. If you want to update the global variable value you can assign the value and retrieve the same at any time.
Code:
'Step 1: Create a .vbs file and map that to your test.
'Step 2 : Now create a global variable in the library file.
Dim glbVariable : glbVariable = ""
'Step3 :
    'Action 1 : Assign some value to the global variable
    glbVariable = "Value from Action 1"
Step 4:
    'Action 2:Now create another action  and retrieve the value.
    msgbox gblVariable 'the message box should display "Value from Action 1"

Let me know if you need any further information.


RE: Global variables in QTP - rajpes - 07-18-2011

Using a library function is a trick but not standard practice,you can create a globalDictionary and set/get key values in it which can be shared among actions