Jump to content
Macro Express Forums

Clear Variables


Cartwheels

Recommended Posts

Do I need to clear varibles at the beginning of my macros so they don't accidently get recycled? In other words do the varibles get carried over from the last time they were run?

 

I had a macro do something kind of odd, so I'm trying to figure out why it did what it did.

 

You dont have to if you define all the macros in the variable. but depending on the situation like if you are appending to another variable then yes you do

<CLEARVAR1:A:ALL>

clears all variable

 

 

 

 

 

If you explain what happens and maybe post some of the code we can look through it and try to figure it out.

Link to comment
Share on other sites

This has always been a fuzzy area for me, if only because I can't find a clear description in the Help system. But here's an experiment.

 

Consider the following macro:

Text box display %T1% %T2% %T3%

Variable set string T1 = a

Variable set string T2 = b

Variable set string T3 = c

Text box display %T1% %T2% %T3%

 

Every time you run it, the first display will be blank (no values) and the second display will be "a b c". So, it appears that variables have no value carried over from previous macro executions.

 

Now run a second macro consisting solely of

Text box display %T1% %T2% %T3%

 

Every time you run it, the display will be blank (no values). That is true even if you run the first macro and then the second -- the display will still be blank.

 

Now, add "Save all variables" to the end of the first macro, and "Restore all variables" to the beginning of the second macro. Run the first macro followed by the second.

The first display from the first macro will always be blank.

The second display from the first macro will be "a b c".

The (only) display from the second macro will be "a b c".

 

So it appears that all variables are empty by default when a macro begins, and values set within a macro are discarded when the macro ends, UNLESS save and restore are used. The exception to this rule is, when the MACRO RUN command is used to call one macro from within another, the called macro automatically inherits all values existing in the caller.

 

Saved variable values do not survive a shutdown and restart of Macro Express.

 

I only tested with text variables. You could extend the test to include decimals and integers. My guess is that they act the same way.

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