May 12, 2009

The Variable Explorer

Filed under: Automation,General,Scripting — Marcus Tettmar @ 2:15 pm

An experienced Macro Scheduler scripter was recently trying to figure out why the following code wasn’t doing what he expected:

If>seg_1=05
  Let>monLtr=mm
Endif

Apparantly monLtr was always being set to 05.  This told me that “mm” must have been a variable which had earlier been set to 05.   But my friend said “I’ve looked all through the code I can’t see where “mm” is set anywhere”.  

Then I reminded him of the Variable Explorer.  “The what?” he asked.

varexplorerUnder the editor select Tools/Variable Explorer or hit Ctrl-Alt-V and you’ll get a box like this one.  It shows a list of all the variables created by your script.  

Bingo!  There’s mm.  Expand it and you’ll see all the lines where it is set/created.   In this case it’s created on line 40 by the Min command.  

In a long script it’s easy not to see the obvious.  The Variable Explorer makes it easier.

Of course, it would also be sensible to use a better naming convention for the variable to avoid such confusion.  Or use VAREXPLICIT or he could have used {“mm”} to specify the literal string value.   But don’t forget the Variable Explorer as it can save a lot of hunting around.