Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regarding Global Variable in QTP
#1
Solved: 10 Years, 9 Months ago

i want to create a global variable and use it across different action and methods.

I used environment variable but i m not able to do it.
I want to create a Excel application object and used it in different action .
Can you provide me the code or logic.
Reply
#2
Solved: 10 Years, 9 Months ago
Can you please list out the steps you did to create an environment variable?
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
#3
Solved: 10 Years, 9 Months ago
Code:
set objExcel=createobject("excel.application")
environment.value("wbk")=objExcel.workbooks.open("somepath")

now i wnt to use this wbk object in my function libaray

public function a()
  set objworkbooks=environment.value("wbk")
  set objworksheets=objworkbooks.sheets
end function

but it show some error objworkbooks dnt hve sheets method
Reply
#4
Solved: 10 Years, 9 Months ago
Two things,
1. I dont understand your objective. What are you trying to achieve? what do you want to store in your environment variable?
2. did you create the environement variable under test settings->Environment->Userdefined?
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: 10 Years, 9 Months ago
My objective is to create a object.suppose i wnt to create a database connection.now i m not going to create database connection every time .so i create one and used it whrever it needed.For that purpose i m trying to create global variable which i create in one script and used it in different functions.
Reply
#6
Solved: 10 Years, 9 Months ago
If you want to create an object and use it across use it as a function. You can call this function in your various actions.
Here is how environment variable works,

Code:
Under Action 1:
                     Environment.Value("oStringValue") = "LearnQTP"
In Action 2, Action 3, Action 4..etc etc. you can access this stored value as,
  oMyVar = Environment.Value("oStringValue")
msgbox oMyVar ' this will give you LearnQTP which is the value the variable holds.
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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading Global Sheet's DataTable Value Bhuvana 0 1,472 01-05-2020, 10:03 PM
Last Post: Bhuvana
  Error as Global Not defined while trying to retrieve value from Datatable siddharth1609 0 848 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,048 06-02-2015, 09:19 PM
Last Post: M Adnan Iftikhar
  global object which can be called in any action excellentpawan123 2 2,579 04-01-2015, 07:34 PM
Last Post: babu123
  Sometimes there is Global datasheet. utestqa 0 2,471 10-02-2013, 07:09 PM
Last Post: utestqa

Forum Jump:


Users browsing this thread: 1 Guest(s)