Variable Scope

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
gchichester
Pro Scripter
Posts: 132
Joined: Mon Dec 22, 2008 4:56 pm
Location: St Augustine FL

Variable Scope

Post by gchichester » Tue Jan 26, 2016 7:14 pm

MS Help states that "All variables have global scope (are available to the entire script once created)."
Does this include macros that are called (Macro>C:\MacroName.scp) from within the main script?
If not what is the best way to include them in the called macro?
Thank you in advance for all your help
Gil

gchichester
Pro Scripter
Posts: 132
Joined: Mon Dec 22, 2008 4:56 pm
Location: St Augustine FL

Re: Variable Scope

Post by gchichester » Tue Jan 26, 2016 7:25 pm

I dug a little further and found my answer
Sorry I posted a little to soon.

Gil
Thank you in advance for all your help
Gil

User avatar
Meryl
Staff
Posts: 124
Joined: Wed Sep 19, 2012 1:53 pm
Location: Texas
Contact:

Re: Variable Scope

Post by Meryl » Mon Feb 01, 2016 2:05 pm

Mind sharing your answer in case someone else wants to know?

gchichester
Pro Scripter
Posts: 132
Joined: Mon Dec 22, 2008 4:56 pm
Location: St Augustine FL

Re: Variable Scope

Post by gchichester » Mon Feb 01, 2016 2:18 pm

Just so happens i found the answer in the MS Manual

A word or two should be said about other scripts called or included by your script.
If the Macro command executes another macro. That macro is kept separate from the calling macro. In this instance variables are not shared, so scope could be said to be local. Using the Macro command is like calling a separate process via the command line. Variables can be passed into the called macro via command line parameters, but script variables within the code are not shared. In contrast the Include statement, rather than "call" the included macro file, literally includes the code from that file within the main script. Include is rather like copying and pasting the code from the Include file into the main script file at run time. Therefore in this instance variables are shared as the Included script becomes part of the main script.

Hope this helps

Gil
Thank you in advance for all your help
Gil

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts