Using Global variables in Unit Script
Trying to learn scripting, and have a simple script that opens a webpage and logs in. I have successfully gotten this to work using local variables, however I want to use persistent variables that can be reused in other scripts. So I created a new variable with a type of 'String' as such:
Name: PageLink
Type: String
Default Value: http://www.mypage.com/login/
Local Value: http://www.mypage.com/login/
In my script, I can open the browser to the page if I set the variable locally, i.e:
Sub Login Dim Env Env = "http://www.mypage.com/login/" Browsers.Item(btIExplorer).Run Env End Sub
That will open IE to the page set in 'Env'.
If I try using my global variable:
Sub Login Dim Env Dim Variables Set Variables = ProjectSuite.Variables Env = Variables.VariableByName("PageLink") Browsers.Item(btIExplorer).Run Env End Sub
Then I get the error message: "The Variables object does not contain a variable with the "PageLink" name".
I'm not quite sure what I'm doing wrong, or how I can tell my local variable to get its value from my global variable?
When you create a variable in the Project/ProjectSuite, It autocompletes after typing Project.Variables.
Dekks wrote:
Sub Login Dim Env Dim Variables Set Variables = ProjectSuite.Variables Env = Variables.VariableByName("PageLink") Browsers.Item(btIExplorer).Run Env End Sub
You do not need to go like this much lines code to get your variable. Just do like below after creating a variable.
Browsers.Item(btIExplorer).Run ProjectSuite.Variables.PageLink