Jump to content
Macro Express Forums

Saving Variables


margaret

Recommended Posts

Apparently the only way to save variables is to save all variables of a certain category (all text variables, for example). Is that correct? There's no way I can just save one particular variable?

 

Thanks.

I'm pretty sure that is correct (except that you can also save all variables of all types with a single command, of course).

 

I've looked for ways to save just one specific variable in the past and I'm confident that there isn't any way. Not that it should

necessarily matter though. If you save all Text variables, and T1 is the only one you actually care to keep, it shouldn't matter. When

you run the "Restore" command later, there is no obligation to use any of the other variables previously saved.

 

However if you have something like this:

Macro A

Set T1 = Hello!

Set T2 = See ya!

[Various Macro Code]

Save All Variables

 

Followed by:

Macro B

Set T1 = Jumpin' Geewillikers!

Set T2 = Danger Will Robinson, Danger!

[Various Macro Code]

Text Type T1

Text Type T2

Restore All Variables

Text Type T1

Text Type T2

 

You may run into some problems... assuming you want T2 to say "See Ya" at the very end, but you want T1 to still say "Jumpin'

Geewillikers!" In this case you would want to put a Save All Variables after setting T1 to "Jumpin' Geewillikers" (but before changing T2

to "Danger Will Robinson").

 

The best thing to do, in my personal experience, is to avoid this kind of complication by using a new variable as often as possible. It

can get a bit confusing, so if you utilize a lot of macros you may want to also build a spreadsheet helping you to keep track of which

variable is used for which information or which kind of information. For example, T99 is solely used to hold Account Numbers in

my macros, whereas T1-T10 are my "throw-away" variables - the variables I will use in just about every macro specifically for that

macro (or series of macros, if I generally run the same 2 or 3 in a row in the same sequence). Any information being saved to a

variable that I may need to call back sporadically, or otherwise not immediately gets saved to various other variables. For example, I

have 10 different clipboard-copy commands (and 10 corresponding clipboard-paste commands) that I picked up off the Macro Express

website. The default variable locations are T10-T19 (I think), but I changed them to T81-T90 since I use the lower numbers on various

occasions and don't want to mess up my clipboards.

 

And even better option is to upgrade to ME Pro where you can define your variable names. You are no longer limited to 99 text

variables, 99 Integer Variables, and 99 Decimal Variables. You still have access to use T1 - T99, but you can create unlimited additional

variables that you name yourself, such as %accountnumber% and %clipboard%. And you can even build arrays of these variables

(such as %clipboard[1]% - %clipboard[99]% etc.

 

Good luck!

Link to comment
Share on other sites

It's a little extra effort, but you can save a Txx variable to an environment variable, which you can call anything you want. You can indirectly save a Dxx or Nxx variable to an environment variable by first converting it to text -- then of course you have to convert it back when you retrieve it.

 

I have several groups of macros that must coexist on the same PC. Each group is consistent within that group as to how the variables are used; but the groups could step on each other. So I wrote separate save-variables and restore-variables macros for each group. All 99 integer variables are converted to text and stacked (space delimited) in a single text variable that is then saved in an environment variable. All 99 decimal variables are likewise converted and stored in a single environment variable. The 99 text variables must each be stored in its own individual environment variable. They can't be stacked unless you can come up with a delimiter character that will never appear as valid text.

 

The above works well, runs surprisingly fast, and is a royal pain in the butt. When I convert to ME Pro, one of the first things to do will be assign unique names to critical variables.

Link to comment
Share on other sites

I'm pretty sure that is correct (except that you can also save all variables of all types with a single command, of course).

.....

 

The best thing to do, in my personal experience, is to avoid this kind of complication by using a new variable as often as possible. It

can get a bit confusing, so if you utilize a lot of macros you may want to also build a spreadsheet helping you to keep track of which

variable is used for which information or which kind of information. For example, T99 is solely used to hold Account Numbers in

my macros, whereas T1-T10 are my "throw-away" variables - the variables I will use in just about every macro specifically for that

macro (or series of macros, if I generally run the same 2 or 3 in a row in the same sequence). Any information being saved to a

variable that I may need to call back sporadically, or otherwise not immediately gets saved to various other variables. For example, I

have 10 different clipboard-copy commands (and 10 corresponding clipboard-paste commands) that I picked up off the Macro Express

website. The default variable locations are T10-T19 (I think), but I changed them to T81-T90 since I use the lower numbers on various

occasions and don't want to mess up my clipboards.

 

And even better option is to upgrade to ME Pro where you can define your variable names. You are no longer limited to 99 text

variables, 99 Integer Variables, and 99 Decimal Variables. You still have access to use T1 - T99, but you can create unlimited additional

variables that you name yourself, such as %accountnumber% and %clipboard%. And you can even build arrays of these variables

(such as %clipboard[1]% - %clipboard[99]% etc.

 

Good luck!

 

A spreadsheet -- that is a truly great idea! I'm used to VBA where I can name variables with names that have some connection to reality. In the last macro I wrote, I had to write out pseudocode with imaginary meaningful variable names and put the Txx and Nxx numbers above the meaningful names in order to figure out what I needed.

 

ME Pro sounds great for me, but what I'm doing is creating a set of macros for other people, who won't want to get ME Pro. I would assume that plain ME can't read the custom-name variables that you create in ME Pro, right?

 

Thanks for the suggestions.

Link to comment
Share on other sites

It's a little extra effort, but you can save a Txx variable to an environment variable, which you can call anything you want. You can indirectly save a Dxx or Nxx variable to an environment variable by first converting it to text -- then of course you have to convert it back when you retrieve it.

 

I have several groups of macros that must coexist on the same PC. Each group is consistent within that group as to how the variables are used; but the groups could step on each other. So I wrote separate save-variables and restore-variables macros for each group. All 99 integer variables are converted to text and stacked (space delimited) in a single text variable that is then saved in an environment variable. All 99 decimal variables are likewise converted and stored in a single environment variable. The 99 text variables must each be stored in its own individual environment variable. They can't be stacked unless you can come up with a delimiter character that will never appear as valid text.

 

The above works well, runs surprisingly fast, and is a royal pain in the butt. When I convert to ME Pro, one of the first things to do will be assign unique names to critical variables.

 

It's a text variable that I want to save, so that sounds as if it would work. I'll try it.

 

I guess this is a new question, but I have a macro that calls another one, and I don't seem to have to save/restore the main variable (the main macro copies the clipboard, the called macro manipulates that text in various ways, then the main macro takes over and does more stuff, and supplies the modified text to another program a few steps later. It works without saving/restoring the variable. Apparently I only have to save/restore the variables if they'll be used by a different macro entirely (in the same session), that runs separately from the macro in which I saved the variable -- but not if they're being used by a macro called while the original macro is running. I've wondered how "safe" this is to do, but it helps me because all the macros used this called routine, so if I want to modify it, I'll only have to modify that one macro instead of all of them.

Link to comment
Share on other sites

ME Pro sounds great for me, but what I'm doing is creating a set of macros for other people, who won't want to get ME Pro. I would assume that plain ME can't read the custom-name variables that you create in ME Pro, right?

You're correct. ME 3 macros are portable to ME Pro, but ME Pro macros are not reverse-compatible with ME 3.

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