Jump to content
Macro Express Forums

Global Or Local Variables?

Carlos Garcia

Recommended Posts



I'm planning for a group of macros to call each other or not in sequence based on certain conditions I don't need to go into. These macros are basically subroutines of a larger task.


I have reused much of the "code" from one subroutine to the other. Therefore I need to know if variable "N1" in "Macro_1" is set to "Apples", then Macro_1 calls Macro_2 as it's last instruction before it terminates will the value within "N1" be initialised as "Apples" if this variable is used in Macro_2?


In other words to variable values "carry over" into other macros?


Needless to say is this happens it's going to be extra work for me...


Thanks in advance.

Link to comment
Share on other sites

Welcome to the group Carlos!


All variables in Macro Express are global in scope. It does not matter in which level within a chain of callable macros the variable is set or reset. All other macros, up-and-down the calling chain will use the same variable and variable value. In other words, you may have an unlimited number of macros calling other macros, but they will all use the same T1-T99, N1-N99, and D1-D99 set of finite variable tags.


This will be true for as long as the current macro session is running. Once a new macro session is fired, all variables are immediately set back to their default empty or zero values. A macro session starts when a macro, or chain of macros, begins execution and ends when it, or they, stop.


You should look into the native Variable Save and Variable Restore commands. These will allow you to save an instance of a variable before changing it and then restore it back again. If you need to save and restore more than a single instance of a variable, then there are routines available in our PGM Functions Library that will allow you to save and restore up to sixteen levels of variables.

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.

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.

  • Create New...