Jump to content
Macro Express Forums

Sharing: Variables Management


oicqcx

Recommended Posts

As every M.E. user kown, the life of variables in M.E., even between macros, is the whole life cycle of the macro, from start to the end. This will cause serious coupling problem while devloping a macro, especially in a set of macros.

 

After consideration, I wrote a set of macros to avoid variables coupling. It works as follow.

Use windows registry as a buffer of variables, every time, before a macro invoke another, save all the variables to the registry. Here, we got a problem, if macro A invoke macro B, and macro B invoke macro C, in this situation, variable saved in buffer would overwirte by macro B. It is easy to solve this problem, we need a registry value, level, let's say, to save the current invoke level. So, every macro saves their variables to their own level buffer.

When a macro invoked finished its job and return to the invoker, what we need to do is to delete the buffer.

 

a simple example, macro A needs to invoke macro B while A is running. A and B both has several variables. the representative code for macro A would like this.

 

...some thing to do...
Macro Run: VariableSave
Macro Run: B
Macro Run: VariableRestore
...some thing to do...

 

mimetic, if macro B needs to invoke macro C, the code for macro B would like:

...some thing to do...
Macro Run: VariableSave
Macro Run: C
Macro Run: VariableRestore
...some thing to do...

 

Maybe, you now got a question. if macro B crashes caused by unkown error, what to do? Will these variables management macro be disable to perform what they should do? The answer is NO, this will just cause a trash buffer. So, I advice you to call the macro: ResetVariableBuffer in your first macro to fix the fault.

 

As experienced M.E. user, I found that in a macro, 10 variables would be enough. so, the macro VariableSave only saves 10 variables, including T, N, D. Importance, I do not save C type variable. The macro VariableSave25 will save 25 variables. The macro VariableRestore25 will restore 25 variables.

 

You can find more information about this utility in this mex file, in the example macro.

 

any advice or bug reporting would be appreciated, can be sent via email:

oicqcx@hotmail.com

vm.mex

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