Micro Focus QTP (UFT) Forums
how to Initialize 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: how to Initialize Environment Variable (/Thread-how-to-Initialize-Environment-Variable)



how to Initialize Environment Variable - jjluna - 06-22-2011

Hello there,

I have a library file that is being used by all scripts, for some functions I use Environment Variables to pass values between scripts, my question is:

How to initialize a Environment Variable?

For example, I have a script that call a function x, Function x uses Environment.Value("Test123"), but the script that is calling function x did not initialize Test123....so when it runs, I get an execution error.

I know the correct way is to initialize the variable, but if for a reason I don't, how to validate Test123 exist and if doesn't to initialize it with a default value?

Thanks for your help.


RE: how to Initialize Environment Variable - souvikghosh_diatm - 06-27-2011

Well in this case u can bring a concept of .xml file which will be used as common environment variable. Just create "a.xml", initialize the environment variable there in following format---

Code:
<Environment>
        <Variable>
        <Name>Test123</Name>
        <Value>Enter value here</Value>
    </Variable>
</Environment>


Now call this environment variable in your function library like following by its name,this will be accessed by all scripts--

Environment.Value("Test123") ---this will return u --"Enter value here" in function library...

Now its the most important part...
Open your test (From which u called that function) in QTP and go to File-->Settings-->Environment Tab-->Select USER DEFINED from drop down-->Check the checkbox "Load Variable......"-->browse that particular xml file. and click ok.

now you are done...now u can access that environment variable from your script through function. Whenever your script will call "Function x" where that environment value is accessed, just load this xml file with that script from which you want to call that function which are accessing that environment variable....


Hope i am clear to u....if there is any doubt, just drop me a mail in souvikghosh.diatm@gmail.com...because i often check these replies...


RE: how to Initialize Environment Variable - jjluna - 07-01-2011

Thanks a lot for the info, really helpful.


RE: how to Initialize Environment Variable - souvikghosh_diatm - 07-02-2011

you are most welcome dear.....