Jump to content
Macro Express Forums

Passing variables on to other macros via Run command


Recommended Posts

If the "Wait for this macro to terminate before proceeding" is unchecked, it does seem apparent the variables cannot be passed from one macro to another using the Macro Run command.

The '"Make this variable available to macros called by this macro" means nothing from my current testing. I found a thread from 2010 that came to this same conclusion as well. Basically they become they 2 stand alone macros? Is this still the case? What is the next best work around?

Link to comment
Share on other sites

  • Cartwheels changed the title to Passing variables on to other macros via Run command

I just got stuck on this same issue.  Unless “Wait for this macro to terminate before proceeding" is check-marked, the variables will NOT be available to called macros.  I suppose this makes sense, because do you want two macros, running in parallel, accessing/modifying the same variable?  Actually, you could argue this both ways – it would be a great way to coordinate activity between two parallel macros.
 
Registry entries and Environment Variables can be used to pass data.  They are a bit clumsier to use but are not subject to the ME limitation.  Personally I stick to Environment Variables because monkeying with the Windows Registry makes me nervous.  But Environment Variables belong to Windows, and as far as I know they cannot be created on the fly from within ME (if anyone knows different please tell me).  Below are my reminder notes on Environment Variables.  I have used this method as far back as ME version 3 to pass tens-of-thousands of bytes among macros.

 

Environment Variables in Macro Express
To create and use one, other than the standard Windows variables:
1. Start Macro Express from a batch file, and within the batch file define the variable; this example creates environment variable “env9999” and sets value “abc”.  (I think all environment variables are text.)
     set env9999=abc
     cd\"C:\Program Files (x86)\Macro Express Pro 6\"
     "C:\Program Files (x86)\Macro Express Pro 6\MacExp.exe"
     exit
2. Now the environment variable can be used within ME -- can be given other values with an option of the Variable Modify String command; and the value can be retrieved with Variable Set String.  

 

For low frequency macros, when timing is not critical, I sometimes use TXT files to pass data.  Delete any previous file if it exists, use Variable Modify String to “append to text file”.  Then in the called macro, use Text File Begin Process to read the text file and get the saved value.  It’s not an elegant method, but it works, and in practice is fast as the blink of an eye.  

 

  • Like 1
Link to comment
Share on other sites

Create two macros:

 

Macro nickname: 1Testing

Activation: A hotkey you can easily remember, e.g., the Insert key, Ctrl+T, or whatever.

 

Variable Restore: Restore All Variables
Variable Set Integer %CurrentSecond%: Set to the Current Second
Variable Save: Save All Variables
Macro Run: 2Testing

<VARIABLE RESTORE Option="\x00"/>
<VARIABLE SET INTEGER Option="\x15" Destination="%CurrentSecond%"/>
<VARIABLE SAVE Option="\x00"/>
<MACRO RUN Use_ID="FALSE" Name="2Testing" ID="-1" Wait="TRUE"/>

 

Macro nickname: 2Testing

Activation: None.

 

Variable Restore: Restore All Variables
MessageBox: Status

<VARIABLE RESTORE Option="\x00"/>
<MESSAGEBOX Caption="Status" Message="Current second is %CurrentSecond%" Icon="2"/>

 

The first macro generates a value based on the current second. The value is stored in an integer variable called %CurrentSecond%.

 

The second macro, which is called by the first macro, outputs the value of %CurrentSecond% in a message box.

 

When I press the hotkey to activate the first macro, the script assigns a value to %CurrentSecond%. The value is passed on to the second macro, which displays the value.

 

To confirm the value is getting passed from the first to the second macro, repeat.

  • Like 1
Link to comment
Share on other sites

1 hour ago, acantor said:

Create two macros:

 

Macro nickname: 1Testing

Activation: A hotkey you can easily remember, e.g., the Insert key, Ctrl+T, or whatever.

 

Variable Restore: Restore All Variables
Variable Set Integer %CurrentSecond%: Set to the Current Second
Variable Save: Save All Variables
Macro Run: 2Testing

<VARIABLE RESTORE Option="\x00"/>
<VARIABLE SET INTEGER Option="\x15" Destination="%CurrentSecond%"/>
<VARIABLE SAVE Option="\x00"/>
<MACRO RUN Use_ID="FALSE" Name="2Testing" ID="-1" Wait="TRUE"/>

 

Macro nickname: 2Testing

Activation: None.

 

Variable Restore: Restore All Variables
MessageBox: Status

<VARIABLE RESTORE Option="\x00"/>
<MESSAGEBOX Caption="Status" Message="Current second is %CurrentSecond%" Icon="2"/>

 

The first macro generates a value based on the current second. The value is stored in an integer variable called %CurrentSecond%.

 

The second macro, which is called by the first macro, outputs the value of %CurrentSecond% in a message box.

 

When I press the hotkey to activate the first macro, the script assigns a value to %CurrentSecond%. The value is passed on to the second macro, which displays the value.

 

To confirm the value is getting passed from the first to the second macro, repeat.

Confirmed, this does work! That is excellent! It looks like the work around is to Save All The Variables in macro one and then Restore All Variables in Macro 2. At first I thought it was only working because Wait="TRUE" and once Wait is unchecked it would not work, but it does in fact work!

 

If you plug in the second Macro Run with the Wait ="False" instead of the one Wait="TRUE", it does still work and is easy to use.

<MACRO RUN Use_ID="FALSE" Name="2Testing" ID="-1" Wait="TRUE"/>
<MACRO RUN Use_ID="FALSE" Name="2Testing" ID="-1" Wait="FALSE"/>
Link to comment
Share on other sites

11 hours ago, Cory said:

I don't have time to read all these messages so I'll just pop this in. Sorry if it's not applicable. 

http://bluepointdesign.com/macros/GlobalLocal/Default.aspx

I wrote this long ago. 

Thanks Cory. Yes this is on point. You can imagine my surprise when I made a few minor changes to my macro including unchecking the “Wait for this macro to terminate before proceeding" box saving and assuming it would still work just fine. Two weeks later, what the heck! It's no longer working. Then it took a while to diagnose the problem because it had been working. There is no end to the learning with this stuff!

Link to comment
Share on other sites

I started reading Cory's explanation about local and global variables, and realized my understanding of how variables get passed from one macro to another might be incorrect.

 

So I created simplified versions of 1Testing and 2Testing that DON'T save and restore the variables:

 

1Testing

Variable Set Integer %CurrentSecond%: Set to the Current Second
Macro Run: 2Testing

<VARIABLE SET INTEGER Option="\x15" Destination="%CurrentSecond%"/>
<MACRO RUN Use_ID="FALSE" Name="2Testing" ID="-1" Wait="TRUE"/>

2Testing

MessageBox: Status

<MESSAGEBOX Caption="Status" Message="Current second is %CurrentSecond%" Icon="2"/>

 

To my surprise, the simplified macros work!

 

Thank you Cory for taking the time to write that description!

Link to comment
Share on other sites

At Macro Express version 3, Variable Save and Variable Restore can allow a group of related macros to work with a single set of variables.  Any macro in the group has access to values previously set and/or modified by other macros in the group.  BUT -- ME version 3 allowed only one macro to run at one time.

 

With ME versions 4/5/6, where multiple macros can run in parallel, it seems that Saves and Restores could overlap in unintended ways, so changes made by one macro would be undone by another. 

Link to comment
Share on other sites

  • 2 months later...

I have to add to my remarks (above) about Environment Variables within ME. 

 

In addition to the standard variables maintained by Windows, Environment variables can also be created on-the-fly within a macro, using Variable Modify String; and retrieved with Variable Set String:
Variable Modify String: Save %text% to Environment Variable, %sav_env_var%    [save value]
Variable Set String %text% to Environment Variable, %sav_env_var%        [retrieve value]

It is a bit confusing, because the Variables tab of the Editor does not allow you to define an environment variable, and an on-the-fly environment variable is not listed as such by the Editor.  An on-the-fly environment variable apparently does NOT survive a shutdown of Macro Express. 

 

Sorry for the confusion -- I found a macro where I have been doing this for years, since way back in ME3! 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...