Greetings! I have a main macro which calls 8 other macros. Each of the subordinate macros needs a certain value. At present, the main macro sets an Excel spreadsheet cell, and each of the subordinate macros reads that cell. Since quite a bit of logic is involved in reading a spreadsheet cell and stripping off the CRLF at the end of the value, it would be nice if the main macro could set a global variable which could then be read by each of the subordinate macros. But I haven't found a Global Variable feature in Macro Scheduler. The only other possibilities would be:
1) The main macro passes a value to each of the subordinate macros.
2) The main macro setting a System Variable (But I haven't figured out how a subordinate variable can read a System Variable set by the main macro. The subordinate macros seem to be unaware that the main macro has set a System Variable.
3) Have the main variable create a file which is read by the subordinate macros.
4) Have the main macro write to the clipboard prior to calling each subordinate macro.
5) Have the main macro set an Environment Variable which is read by each subordinate macro.
Any help here will be greatly appreciated.
Sincerely,
Michael D Fitzpatrick
Global Variables
Moderators: JRL, Dorian (MJT support)
-
- Pro Scripter
- Posts: 56
- Joined: Sun May 11, 2008 9:39 pm
Global Variables
May you have a blessed day!
Michael D Fitzpatrick
Reg. US Patent Agent
Michael D Fitzpatrick
Reg. US Patent Agent
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Hi,
If you are calling the subordinate macro with the Macro> command then variables are local to the calling script and any variables inside the subordinate script are local to it.
If you use Include> instead of Macro> then the subordinate macro actually becomes a PART of the calling macro and therefore all variables are global to both.
So Include> may be the solution you are looking for.
However, if you are using Macro> you can pass values IN to the called subordinate macro like so:
Macro>c:\bla\subordinate.scp /MyVarA=Something /AnotherVar=SomethingElse
Etc.
You could indeed use Environment variables if you must. Use SetEnvVar and GetEnvVar.
In short, you can do what you want in a number of different ways. Sounds like Include> might be what you are looking for.
Note that since Include literally sucks the subordinate macro into the calling macro - they become one - when you debug and step through the calling macro you will actually SEE this happen and the code becomes one. So you can even debug a complete process that uses Includes.
If you are calling the subordinate macro with the Macro> command then variables are local to the calling script and any variables inside the subordinate script are local to it.
If you use Include> instead of Macro> then the subordinate macro actually becomes a PART of the calling macro and therefore all variables are global to both.
So Include> may be the solution you are looking for.
However, if you are using Macro> you can pass values IN to the called subordinate macro like so:
Macro>c:\bla\subordinate.scp /MyVarA=Something /AnotherVar=SomethingElse
Etc.
You could indeed use Environment variables if you must. Use SetEnvVar and GetEnvVar.
In short, you can do what you want in a number of different ways. Sounds like Include> might be what you are looking for.
Note that since Include literally sucks the subordinate macro into the calling macro - they become one - when you debug and step through the calling macro you will actually SEE this happen and the code becomes one. So you can even debug a complete process that uses Includes.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Pro Scripter
- Posts: 56
- Joined: Sun May 11, 2008 9:39 pm
Using Environment Variables for Global Variables
Greetings! What are the disadvantages of using Environment Variables to set variables globally? For example, my main macro could create and set an Environment Variable named STEP_DELAY as follows:
// Set STEP_DELAY to 200 ms
SetEnvVar>STEP_DELAY,200
Then each of the 8 subordinate macros which are called by the main macro could read that variable as follows:
GetEnvVar>STEP_DELAY,STEP_DELAY
This seems to work but maybe I'm overlooking something. Your help is greatly appreciated.
Sincerely,
Michael D Fitzpatrick
// Set STEP_DELAY to 200 ms
SetEnvVar>STEP_DELAY,200
Then each of the 8 subordinate macros which are called by the main macro could read that variable as follows:
GetEnvVar>STEP_DELAY,STEP_DELAY
This seems to work but maybe I'm overlooking something. Your help is greatly appreciated.
Sincerely,
Michael D Fitzpatrick
May you have a blessed day!
Michael D Fitzpatrick
Reg. US Patent Agent
Michael D Fitzpatrick
Reg. US Patent Agent
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Using Environment Variables for Global Variables
None that I can think of.evangelmike wrote:Greetings! What are the disadvantages of using Environment Variables to set variables globally?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Pro Scripter
- Posts: 56
- Joined: Sun May 11, 2008 9:39 pm
Further findings on use of Environment Variables in Macro Sc
Greetings! Since I penned my last reply, I discovered that the solution I presented fails when a macro is calling a longer (or more complex) macro. After a bit of fiddling around I discovered a solution which seems to always work:
The main macro would have:
and the called macro would have:
Perhaps in a longer or more complex called macro the GetEnvVar fails when the name of the local variable is the same as the name of the environment variable.
And this raises a good question. If one wants there to be no delay between successive instructions, is it better to leave STEP_DELAY undefined (as I have been doing since day 1) or to explicitly define it as follows:
Let>STEP_DELAY=0
I am hoping that both of these are equivalent. It should be mentioned that if one leaves STEP_DELAY undefined, and one then tries to display STEP_DELAY as follows:
what is displayed is just the string STEP_DELAY.
The main macro would have:
Code: Select all
SetEnvVar>SetSTEP_DELAY,200
Code: Select all
GetEnvVar>SetSTEP_DELAY,STEP_DELAY
And this raises a good question. If one wants there to be no delay between successive instructions, is it better to leave STEP_DELAY undefined (as I have been doing since day 1) or to explicitly define it as follows:
Let>STEP_DELAY=0
I am hoping that both of these are equivalent. It should be mentioned that if one leaves STEP_DELAY undefined, and one then tries to display STEP_DELAY as follows:
Code: Select all
MessageModal>%STEP_DELAY%
May you have a blessed day!
Michael D Fitzpatrick
Reg. US Patent Agent
Michael D Fitzpatrick
Reg. US Patent Agent
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Both are equivalent.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?