Cory Posted May 20, 2010 Report Share Posted May 20, 2010 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". Quote Link to comment Share on other sites More sharing options...
paul Posted May 21, 2010 Report Share Posted May 21, 2010 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? Quote Link to comment Share on other sites More sharing options...
Cory Posted May 21, 2010 Author Report Share Posted May 21, 2010 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.