Jump to content
Macro Express Forums

Details Of "save Variables" And "restore Variables


Linda

Recommended Posts

Yes, I understand how they work in simple situations, with say, two macros the first of which calls the second which completes and returns.

 

However, the help-file never says exactly what the saves and restores are doing, just that (in paraphrase) "Uh, yeah- Save Variables and Restore Variables are, like, for passing variables between macros n'stuff." And it describes the simplest situation.

 

In more complex situations, the save and restores have behaved in ways that seemed counter-intuitive to me. So I want to find a description of what, exactly, in technical terms, the save and restores are doing, so that I can predict complex behaiors.

 

Thanks! B)

Link to comment
Share on other sites

Hello Linda!

 

There is no complex behavior associated with the built-in Save and Restore Variables commands. All variables in Macro Express are global in scope. Once defined, they are accessible to any macro, called or calling, in any library, within the same run session. This means that for every Save Variables command, there must be a Restore Variables command before another Save command is invoked or else your saved variables will be overwritten in memory.

 

For a company like ours that creates reusable, callable macro functions, this was not going to work, so we created our own set of Save and Restore functions that are incorporated into almost every function within our PGM Functions Library. This allows us to use the Macro Run command without ever having to worry about overwriting existing variables.

 

One thing that is overlooked with the native Save and Restore Variables is that they can be used between sessions. If, for example, one of the last lines in a macro session is to Save Variables then you can Restore Variables by placing the command at the beginning of the first macro run in the next session.

 

Another thing that is possible with the Macro Express memory space is to pass values to it using command line arguments with MeProc.exe or MacExp.exe.

Link to comment
Share on other sites

Thanks!

 

So... I only need to do Saves and Restores to save values between sessions? That simplifies things (and complicates them)... I thought I had to do it every time I called a subroutine macro (or at least any sub-macro that required even a single argument from it's parent) to pull the sub-macro into the same "namespace" as the parent.

 

But I'm still confused about some of the unexpected behavior I encountered.

 

For instance, I had two macros:

 

 

Macro A:

// Do some stuff. 
// sets up Text variables.
// sets up Integer variavles

Variable Save: Save Interger Variables
Macro Run: Macro B

// The Integer values from B are fine
// ACK! ALL MY TEXT VARIABLES WERE BLANKED OUT!!!

==============

Macro B:
Variable Restore: Restore Integer Variables

// do the same stuff it did before.

 

I now understand that the "save" and "restore" were unncesseary. But why did all my Text variables go away when I did a save and restore of Integer variables? I'm still confused as to why a command refering to Integer variables erased all of my Text variables? :(

 

Sorry if I seem dense here, but I'm finding the help file very unhelpful. (It's trying so hard to sound non-technical and unintimidating to the non-technical person that it generally leaves out whatever bit of info I'm looking for.)

 

BTW, can you reccomend any books on MacroExpress with a more technical slant? I'm going into a bit of withdrawl here, trying to get used to macro programming (as opposed to C++, Perl, Java, etc)

 

Thanks! :)

Link to comment
Share on other sites

Hello Linda!

 

I think that you are confusing the use of the Save and Restore commands with the ability to pass variables from one macro function to another. It appears that I added to the confusion with my previous post. Let me try to explain.

 

Variables are global in scope. They are not passed between functions (er, macros) they are inherited. If, for example, you set %D99% to 3.14159 somewhere in a function that is way down the calling chain then you will see that %D99% will still be 3.14159 when you get back up to the top-level caller. Inheritance ... down and up the chain.

 

But, forget the Macro Run command for the moment. The Save and Restore commands can be used within a single function, too. If you set %D99% to 3.14159, then Save it, then set %D99% to .70711, then Restore variables, %D99% would be back to 3.14159. The only thing that the Save command (or any variation of it) does, is to copy the current variables into Macro Express memory space, allowing you to change them to something else temporarily.

Variable Set Decimal %D99% to 3.14159
Variable Save All Variables
Variable Set Decimal %D99% to .70711
Variable Restore All Variables //D99 is now back to 3.14159

Using a variation of the Save and Restore command for just integers does not affect any other type of variable. This is true for any of the variations. I can only guess that something else happened to erase them.

 

The only book written about Macro Express that I am aware of is the one that I wrote ... Macro Express Explained ... so I heartily recommend it! :rolleyes:

 

... and guess what chapter I wrote first. Right ... Variables ;)

Link to comment
Share on other sites

I think that you are confusing the use of the Save and Restore commands with the ability to pass variables from one macro function to another. It appears that I added to the confusion with my previous post. Let me try to explain.

 

I was, but your first response cleared that up :). I confused the matter by including an old example, and saying things like "Since at the time I thought..." which unnecesisarily complicated the issue. I've edited my second post to (hopefully) remove the confusion of my example.

 

Except... when I tried to create a simplified example (as I should have done before my initial post), I didn't see the behavior I complained about above, so my error must have been elsewhere, and I was unfairly blaming variable behavior.

 

So nevermind on the variable question in the second post. And thanks for your help clarifying the variable issue!

 

The only book written about Macro Express that I am aware of is the one that I wrote ... Macro Express Explained ... so I heartily recommend it!

 

I'll check it out.

 

... and guess what chapter I wrote first. Right ... Variables  ;)

Good choice B) . It's the most basic part of any programming language, yet so poorly explained in the help files...

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