Jump to content
Macro Express Forums

Clear Variables doesn't clear Global


Recommended Posts

Clear Variables > Clear All of this Type executed in a called macro does not clear global variables from the parent. My question is do you macro writers consider this a bug or should it work this way? I can think of arguments either way.

 

Example: Macro A sets the global string variable %test% to "something" and then runs macro B. Macro B which has %test% defined as a global clears all text variables then displays %text%. But the text box now shows "Something".

Link to comment
Share on other sites

Clear Variables > Clear All of this Type executed in a called macro does not clear global variables from the parent. My question is do you macro writers consider this a bug or should it work this way? I can think of arguments either way.

 

Example: Macro A sets the global string variable %test% to "something" and then runs macro B. Macro B which has %test% defined as a global clears all text variables then displays %text%. But the text box now shows "Something".

Interesting question. My answer would be: it depends whether MEP has any concept of ownership of variables. If Yes, then only Macro A should be able to clear %test%; if no, then your example should have worked as you expected.

 

Now try your test again, this time making %Test% an array of 1 element, and changing all references to %test% to %test[1]%. Leave the Clear Variables command as is, i.e. Clear all Text variables. Run Macro A again, and there's no change in behaviour.

 

Finally change the Clear Variables command to clear only the 1st element of %test%, and it now behaves as you probably expected in the first place. IMHO that's now become a bug, because variables should behave the same whether they are arrays or not. Do you agree?

Link to comment
Share on other sites

Yeah I've been discussing this offline with others as well and I think the consensus is that it should not work this way. The simplest way to think of it for me is that if macro B can change the variable value to something else then it follows that it should be included in the set of "All" in Clear All Variables. IE "All" should be everything in it's scope. Especially if you consider that it's defined in macro B as well.

 

In VB I recently learned about scoping and thought of some examples where one would have a variable at the procedure level but also variables at a block level which still use the upper level variables. Anyway it led me to think of some logical reasons why this might be by design. BTW block level scope is really cool. I can define variables like counters and don't have to do any clean up and they disappear when the loop or conditional block is over.

 

Thanks for the input and the sanity check.

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