Jump to content
Macro Express Forums

Save / Restore Within Called Macros


Recommended Posts

Hi all,

 

This question is for Kevin, Stan, Jason, or anybody else who really knows the answer (speculation is fun, but I just need to know

the truth).

 

In a previous thread Cory helped me to finally grasp the Macro Called concept with regards to Global variables and for that I'm grateful.

However, in the course of that thread a new situation reared its head (strange term, that: rear one's head... nothing at all like heading

one's rear... I digress).

 

For lack of a better diagram, I'll use the same as established in that thread:

3 Macros (A, B, and C) in which A calls B and then calls C.

B creates a named variable %var%

C uses that variable

 

If A does not have %var% defined then by the time A calls C, the contents of %var% are lost. Cory helped me understand why, and

even suggested that I put %var% in A and not in B or C (he explained that even without it established within the called macros, as long

as it is Global in A, then the macro will run fine). I can do that, it's not a problem.

 

Here are my questions:

If all variables are Saved at the end of macro B and all variables are Restored at the beginning of macro C, then why do the contents of

%var% remain null in C, even if that variable is not defined in A?

 

I accept that the contents of %var% (as established in macro B) will be lost when the macro returns to A; however, should the Restore

command not restore the contents of %var% after they were lost in macro A? If not, can I get a somewhat reasonable explanation as to

why not (other than simply "because you should be defining the variable in macro A," please).

 

EDIT

As an additional side-note: If B is run independently (not called by A), but A still calls C, then the Restore command within C succeeds

at restoring the contents of %var% (as established within B), even though %var% doesn't exist within A. This seems inconsistent to me.

Link to comment
Share on other sites

Well, it's been more than a week without a response explaining why the Save / Restore function doesn't work in the above cases, so is it safe to assume there is no reason? I don't want to submit a bug report unless it actually is a bug.

 

I have quite a few macros that are built in the format of a "parent" macro calling on one or more specialized macros. Save/Restore working within the specialized macros would save me in those instances where I forget to add new variables to the "parent" macro.

 

An even better option would be that when a variable is created, an option to make it available to all macros (like the built in T, N, and D variables). In fact I may just officially submit that as a feature request.

Link to comment
Share on other sites

The term 'Global Variable' is a bit of a misnomer. 'Global Variables' are not global everywhere, they are available to the macro they are defined in and all macros under it (called by Macro Run).

 

So, in your example, variables defined in Macro B are not available in Macro C. Yes, they both have a variable with the same name but they are not the same variable. I agree that we should be able to save variables from one macro and restore them in another. We will look into why this is not working. In the meantime you can get this to work if you assign Global Variables in the main macro (Macro A, in your example).

 

An even better option would be that when a variable is created, an option to make it available to all macros (like the built in T, N, and D variables). In fact I may just officially submit that as a feature request.

We already have a request to allow a set of variables to be assigned when a new macro is created. For the record it is issue [iSS6575].

 

The T, N and D variables in one macro are not the same as the T, N and D variables in another macro. The names are the same but there is a separate %T[1]% variable for each macro that contains separate content.

Link to comment
Share on other sites

The term 'Global Variable' is a bit of a misnomer. 'Global Variables' are not global everywhere, they are available to the macro they are defined in and all macros under it (called by Macro Run).

 

So, in your example, variables defined in Macro B are not available in Macro C. Yes, they both have a variable with the same name but they are not the same variable.

I get that. It wasn't immediately obvious to me, but after much discussion with Cory it finally sank in.

 

I agree that we should be able to save variables from one macro and restore them in another. We will look into why this is not working. In the meantime you can get this to work if you assign Global Variables in the main macro (Macro A, in your example).

 

We already have a request to allow a set of variables to be assigned when a new macro is created. For the record it is issue [iSS6575].

Awesome! Thank you very much for looking into these issues!

 

The T, N and D variables in one macro are not the same as the T, N and D variables in another macro. The names are the same but there is a separate %T[1]% variable for each macro that contains separate content.

I understand the array principle... My point was that I don't have to add a variable named "T" to every macro in order to have it available as it is built-in. But you are addressing something that should be very similar to what I'm looking for with the afore mentioned issue [iSS6575]. And any other issues related to using the same variable in multiple macros and (where the variable will contain the same information) would/will no doubt be corrected by adjustments to the Save/Restore functions.

 

I'm grateful for your reply. Thank you very much!

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...
 Share

×
×
  • Create New...