Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Global variables in QTP
#1
Not Solved
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..
Reply
#2
Not Solved
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.
Thanks,
SUpputuri
Reply
#3
Not Solved
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading Global Sheet's DataTable Value Bhuvana 0 1,675 01-05-2020, 10:03 PM
Last Post: Bhuvana
  Error as Global Not defined while trying to retrieve value from Datatable siddharth1609 0 989 09-11-2019, 02:52 PM
Last Post: siddharth1609
  On Saving Script in QTP 11 my Global Data Sheet data is removed M Adnan Iftikhar 0 2,197 06-02-2015, 09:19 PM
Last Post: M Adnan Iftikhar
  global object which can be called in any action excellentpawan123 2 2,824 04-01-2015, 07:34 PM
Last Post: babu123
  Sometimes there is Global datasheet. utestqa 0 2,740 10-02-2013, 07:09 PM
Last Post: utestqa

Forum Jump:


Users browsing this thread: 3 Guest(s)