//However, it is limited to expansions of variable parameters, not names.
//Variable expansions allow scripts to be greatly simplified.
//Eliminates need for lenghy if statements to evaluate arguments.
//They are also useful for data driven macros where the data is a Macro Scheduler command string.
//In short, this proposal wishes a variable be able to contain a Macro Scheduler command name and parameters and execute it by means of a simple expansion.
// This script illustrates current capabilities, limitations, workarounds, and two proposed solutions.
//Our company's standard is VAREXPLICIT 1
//Should also apply to VAREXPLICIT 0
Let>VAREXPLICIT=1
Include>IncludeLib
gosub>StartEventHandlers
SRT>EvaluateCommand
//EvaluateCommand,CommandString
DeleteFile>C:\tempmacro.scp
WriteLn>C:\tempmacro.scp,nWLNRes,Include>IncludeLib
WriteLn>C:\tempmacro.scp,nWLNRes,gosub>StartEventHandlers
WriteLn>C:\tempmacro.scp,nWLNRes,%CommandString%
Macro>C:\tempmacro.scp
END>EvaluateCommand
SRT>EvaluateCommandArgs
//EvaluateCommand,CommandString
Let>VAREXPLICIT=0
DeleteFile>C:\tempmacro.scp
WriteLn>C:\tempmacro.scp,nWLNRes,Include>IncludeLib
WriteLn>C:\tempmacro.scp,nWLNRes,gosub>StartEventHandlers
WriteLn>C:\tempmacro.scp,nWLNRes,%EvaluateCommandArgs_Var_1%
Macro>C:\tempmacro.scp
Let>VAREXPLICIT=1
END>EvaluateCommandArgs
Let>x=113
Let>y=784
Let>MouseAction1=MouseMove
Let>MouseAction2=LClick
Let>MouseAction3=RClick
////////////////////////////WHAT WORKS ALREADY///////////////////////////
//This works
MouseMove>%x%,%y%
//////////////////////////WHAT DOES NOT WORK//////////////////////
//Command name variable expansions display in the logfile
//but the commands are not executed, so these statements do not work
%MouseAction1%>%x%,%y%
%MouseAction2%
////////////////////////////////// WORKAROUNDS////////////////////////////
//This workaround works
//bury comma in a variable
Let>CommandString=MouseMove>%x%,%y%
gosub>EvaluateCommand
Let>CommandString=LClick
gosub>EvaluateCommand
wait>5
//This variation of workaround is more readable
Let>Command1=MouseMove>%x%,%y%
gosub>EvaluateCommandArgs,%Command1%
Let>Command2=LClick
gosub>EvaluateCommandArgs,%Command2%
//This also works because there are no commas
gosub>EvaluateCommandArgs,RClick
//The readable workaround works fails when commas needed for the parameters
gosub>EvaluateCommandArgs,MouseMove>%x%,%y%
gosub>EvaluateCommandArgs,%MouseAction1%>%x%,%y%
//The only other workarounds involve lengthy "if/else" statements to parse the command string.
////////////////////////CONCLUSION///////////////////////////////
//The workarounds do the job, but incur lots of overhead setting up the temp macro
//The workaround will fail for compiled macros run in a non MS environment.
//A cleaner approach would be to extend the language to expand/execute varibles as commands.
//Example:
%MouseAction1%>%x%,%y%
//Or if that is not feasible, a new Evaluate command that works in current macro's scope.
//Example:
Evaluate>MouseMove,%x%,%y%
Code: Select all