Execute a variable
Moderators: Dorian (MJT support), JRL
Execute a variable
Hi,
If i set a variable to one of the macro command say "Let>check=message>checking command" . Now i want to execute "check".
Is this possible?
If i set a variable to one of the macro command say "Let>check=message>checking command" . Now i want to execute "check".
Is this possible?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Not directly, but you could do this:
Let>check=message>checking command
WriteLn>%TEMP_DIR%\_temp.scp,r,check
Include>%TEMP_DIR%\_temp.scp
..
DeleteFile>%TEMP_DIR%\_temp.scp
Let>check=message>checking command
WriteLn>%TEMP_DIR%\_temp.scp,r,check
Include>%TEMP_DIR%\_temp.scp
..
DeleteFile>%TEMP_DIR%\_temp.scp
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Really neat perhaps, but I'm failing to see the benefit. I've looked also at a very similar enhancement request HERE, and I'm confused as to what purpose can be served by adding another layer to a command function.
Could someone enlighten me?
Could someone enlighten me?
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
This would allow you to create scripts on the fly based on other inputs, database fields, INI files, web site info, etc. I know we can do that now, but using LET> is just a variation.
I don't have an immediate need, but do appreciate the flexibility to do something of that nature. It is nothing more than writing a variable to a file but a variable was created using LET> vs. using the actual text. I have written scp files on the fly before, but usually used the actual text. This just triggers the concept about using other variables to create those commands.
I don't have an immediate need, but do appreciate the flexibility to do something of that nature. It is nothing more than writing a variable to a file but a variable was created using LET> vs. using the actual text. I have written scp files on the fly before, but usually used the actual text. This just triggers the concept about using other variables to create those commands.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
Hi Bob,
Sorry, just re-read my post and I was not very clear. I understand the benefit of writing values to a second script to allow flexibility. What I'm not understanding is the intended process in the original request from aks especially in conjunction with the very similar enhancement request by gdyvig that I mentioned and linked previously. Both are requesting a method to set a function to a variable then somehow be able to execute the variable. I'd like to know why. What is it they want to accomplish?
Perhaps the answer they are both looking for is to write the function(s) to a script file then execute the script file.
Actually, though it is kind of a cool process, the method proposed by Marcus is not my idea of flexible. Once you include the script file, it is as hardcoded into the script as if you wrote it that way. You could not loop back around to the same include> line with a new value for the variable "check" and have the new value executed. You could do that if you instead used the macro> function.
Let>check=message>checking command
WriteLn>%TEMP_DIR%\_temp.scp,r,check
Macro>%TEMP_DIR%\_temp.scp
..
DeleteFile>%TEMP_DIR%\_temp.scp
One advantage of using include> is that in functions that have results, the results remain in the main script. If you use the Macro> function you need to port the results to the main script using the Macro_Result variable.
Sorry, just re-read my post and I was not very clear. I understand the benefit of writing values to a second script to allow flexibility. What I'm not understanding is the intended process in the original request from aks especially in conjunction with the very similar enhancement request by gdyvig that I mentioned and linked previously. Both are requesting a method to set a function to a variable then somehow be able to execute the variable. I'd like to know why. What is it they want to accomplish?
Perhaps the answer they are both looking for is to write the function(s) to a script file then execute the script file.
Actually, though it is kind of a cool process, the method proposed by Marcus is not my idea of flexible. Once you include the script file, it is as hardcoded into the script as if you wrote it that way. You could not loop back around to the same include> line with a new value for the variable "check" and have the new value executed. You could do that if you instead used the macro> function.
Let>check=message>checking command
WriteLn>%TEMP_DIR%\_temp.scp,r,check
Macro>%TEMP_DIR%\_temp.scp
..
DeleteFile>%TEMP_DIR%\_temp.scp
One advantage of using include> is that in functions that have results, the results remain in the main script. If you use the Macro> function you need to port the results to the main script using the Macro_Result variable.
Hi Marcus,
I tried out the steps you have mentioned. I ran the following code snippet:
Let>check=message>checking command
WriteLn>%TEMP_DIR%\_temp.scp,r,check
Include>%TEMP_DIR%\_temp.scp
DeleteFile>%TEMP_DIR%\_temp.scp
I could not see a message box with "checking command" message. I have to get given command execution result. How can i get that in the above code snippet?
Thanks for your response
I tried out the steps you have mentioned. I ran the following code snippet:
Let>check=message>checking command
WriteLn>%TEMP_DIR%\_temp.scp,r,check
Include>%TEMP_DIR%\_temp.scp
DeleteFile>%TEMP_DIR%\_temp.scp
I could not see a message box with "checking command" message. I have to get given command execution result. How can i get that in the above code snippet?
Thanks for your response
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Try using a MessageModal command instead, so that the dialog waits for you to OK it. Also, my script used Include which was new in v10. You may prefer/need to use Macro> instead. So try this:
Let>check=MessageModal>checking command
WriteLn>%TEMP_DIR%\_temp.scp,r,check
Macro>%TEMP_DIR%\_temp.scp
DeleteFile>%TEMP_DIR%\_temp.scp
Let>check=MessageModal>checking command
WriteLn>%TEMP_DIR%\_temp.scp,r,check
Macro>%TEMP_DIR%\_temp.scp
DeleteFile>%TEMP_DIR%\_temp.scp
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
What triggered me to submit the enhancement request
I added an explanation in my enhancement request showing an example of usage for the enhancement, the Evaluate or EvaluateCommand.
I thought it would be useful for all the reasons Bob mentioned, but mainly data driven scripts where a Macro Scheduler command is the action data item. I can be read off a spreadsheet, ini file, or could just be an subroutine or macro parameter.
I don't want my macro or subroutine to need long lists of if or if/else statments like this:
if>%action%=LClick
LClick
endif
if>%action%=RClick
RClick
endif
etc
I thought it would be useful for all the reasons Bob mentioned, but mainly data driven scripts where a Macro Scheduler command is the action data item. I can be read off a spreadsheet, ini file, or could just be an subroutine or macro parameter.
I don't want my macro or subroutine to need long lists of if or if/else statments like this:
if>%action%=LClick
LClick
endif
if>%action%=RClick
RClick
endif
etc
Variables and multiple scripts
Good day all,
Just getting the idea of calling one script with another in my mind but I do have a 'question'. Looking at the solutions, is there a solution to call a script within a script, BUT, the variable declarations stay completely seperate between the scripts and you are literally calling with input and output variables (maybe declarations is the right word here)?
For example:
Script one is looking to display a variable called DisplayValue.
Within our script, we find that we need to add two numbers, Value1 and Value2. So, within script one, we need to call a script call 'add-two-numbers'. So we would perform a command such as:
Let>Result=Script(DisplayValue(Value1,Value2))
Then end result would be:
1. No concern of what the second script is using as variables. No conflicts with the calling script.
2. We could create "modules" of code instead of flat scripts.
Now, I don't currently know if this is possible. If so, I'd love to learn how, but if it's not, is it something that is possible?
Frank.
Just getting the idea of calling one script with another in my mind but I do have a 'question'. Looking at the solutions, is there a solution to call a script within a script, BUT, the variable declarations stay completely seperate between the scripts and you are literally calling with input and output variables (maybe declarations is the right word here)?
For example:
Script one is looking to display a variable called DisplayValue.
Within our script, we find that we need to add two numbers, Value1 and Value2. So, within script one, we need to call a script call 'add-two-numbers'. So we would perform a command such as:
Let>Result=Script(DisplayValue(Value1,Value2))
Then end result would be:
1. No concern of what the second script is using as variables. No conflicts with the calling script.
2. We could create "modules" of code instead of flat scripts.
Now, I don't currently know if this is possible. If so, I'd love to learn how, but if it's not, is it something that is possible?
Thanks very much,Update, I did look at the macro function mentioned within the help files and it seems to satisfy the calling functionality, but do I still have to worry about internal variables between both scripts?
Frank.
Ok, with experimentation I've answered some of my own questions. For the sake of prosperity to others in the future, I will display my results here.
I created the two scripts that I theoritically mentioned in my last post.
Primary script: (calling script)
Adding-two-numbers.scp script: (called script)
Now, the end result of the MessageModal box in the primary script was:
But I have one other question....Is there any way to pass back more then one value to the primary script?
Thanks!
Frank
I created the two scripts that I theoritically mentioned in my last post.
Primary script: (calling script)
Code: Select all
let>FirstVar=1
let>SecondVar=2
Let>ResultingValue=10
Macro>%scriptdir%\Adding-two-numbers.scp /VariableOne=%FirstVar% /VariableTwo=%SecondVar%
Let>ReturnValue=%MACRO_RESULT%
MessageModal>ResultingValue=%ResultingValue% ReturnValue=%ReturnValue%
Code: Select all
//This is a script to add two numbers
Let>ResultingValue=%VariableOne%+%VariableTwo%
let>MACRO_RESULT=ResultingValue
So, the variable in the primary script, ResultingValue, did not get altered by calling another variable in the secondary script the same name. Sweet!ResultingValue=10 ReturnValue=3
But I have one other question....Is there any way to pass back more then one value to the primary script?
Thanks!
Frank
There are multiple ways including writing results of one script to a file then reading them from the other, using putclipboard and getclipboard, using RegistryWriteKey and RegistryReadKey. But to follow your lead the easiest method would be:But I have one other question....Is there any way to pass back more then one value to the primary script?
Code: Select all
//This is a script to add two numbers
Let>ResultingValue=%VariableOne%+%VariableTwo%
let>MACRO_RESULT=%ResultingValue%;%VariableOne%;%VariableTwo%
Code: Select all
let>FirstVar=1
let>SecondVar=2
Let>ResultingValue=10
Macro>%scriptdir%\Adding-two-numbers.scp /VariableOne=%FirstVar% /VariableTwo=%SecondVar%
Let>ReturnValue=%MACRO_RESULT%
Separate>returnValue,;,val
MessageModal>ResultingValue=%ResultingValue%%CRLF%ReturnValue1=%Val_1%%CRLF%ReturnValue2=%Val_2%%CRLF%ReturnValue3=%Val_3%
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Or use Include instead of Macro. The script called by Macro is separate and so scope is local to that macro. In contrast Include includes the code within the calling script so all variables and objects are shared. Therefore any values set by the called code are part of the main script.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Returning multiple parms/variables
Here is an example using an Include script to do the parsing as Marcus suggests. In this example, we use the standard " /" to separate the named parms and "=" to separate parm names from their values.
This solution does not require the "parms" be defined in Macro_Result in any particular sequence.
IncludeMacro.scp
This solution does not require the "parms" be defined in Macro_Result in any particular sequence.
IncludeMacro.scp
CalledMacro.scp//IncludeMacro.scp
SRT>Parse_Macro_Result
//Warning: Array elements still exist from previous invocations of the subroutine
// Do NOT read past arrItems_Count appropriate for current MACRO_RESULT
//Following scheme avoids use of escape characters for / and = in most cases
//Result parm names prefixed with " /"
//Result parm values may contain "/" but not " /" for most URL's and dates
//Result parm values may contain multiple "=" for formulas
//Following statements work regardless of VAREXPLICIT
StringReplace>%MACRO_RESULT%, /,[parm-s-l-a-s-h],MACRO_RESULT
StringReplace>%MACRO_RESULT%,/,[url-s-l-a-s-h],MACRO_RESULT
StringReplace>%MACRO_RESULT%,[parm-s-l-a-s-h],/,MACRO_RESULT
Separate>%MACRO_RESULT%,/,arrItems
Let>arrItems_Count=%arrItems_Count%-1
Let>arrItems_Counter=1
//Some statements inside the Repeat loop require VAREXPLICIT 0
//Switch VAREXPLICIT on/off within the loop fails to work
Let>VAREXPLICIT=0
Repeat>arrItems_Counter
//Repeat iteration arrItems_Counter: %arrItems_Counter%
Let>arrItems_Counter=%arrItems_Counter%+1
//Following statement absolutely requires VAREXPLICIT 0 to capture value of elemnt.
//Nested % not supported
Let>sparm=arrItems_%arrItems_Counter%
//Parm name and value separated with "="
Separate>%sparm%,=,arrparm
Position>=,%sparm%,1,nparmpos,TRUE
Let>nparmpos=%nparmpos%+1
Let>sparmvalue=
if>%nparmpos%>1
MidStr>%sparm%,%nparmpos%,999999,sparmvalue
endif
StringReplace>%sparmvalue%,[url-s-l-a-s-h],/,sparmvalue
Let>arrparm_2=%sparmvalue%
Let>VAREXPLICIT=1
StringReplace>%arrparm_1%, ,,arrparm_1
Let>VAREXPLICIT=0
Let>%arrparm_1%=%arrparm_2%
Until>arrItems_Counter>%arrItems_Count%
//Exited Repeat loop
Let>VAREXPLICIT=1
End>Parse_Macro_Result
CallingMacro.scp (Primary script)//Macro_Result set in called macro
//CalledMacro.scp
//Set ret parms in any sequence
//Each parm preceded by " /"
//Will fail if parm value contains " /"
Let>VAREXPLICIT=1
Let>Macro_Result= /retStatus=Passed /retDate=10/20/2008 /retFormula=E=Mc**2
One undesirable side affect of solutions like this is the noise in the logfile every time Parse_Macro_Result is called.//CallingMacro.scp
//Macro_Result parsed in calling macro
//Our company's standard is VAREXPLICIT 1
Let>VAREXPLICIT=1
Include>IncludeMacro.scp
Macro>CalledMacro.scp
gosub>Parse_Macro_Result
MessageModal>Status: %retStatus%
MessageModal>Date: %retDate%
MessageModal>Formula: %retFormula%
Hi,
I am using the following block of code to execute commands in macro scheduler that are sent by an external script.
WriteLn>%TEMP_DIR%\_temp.scp,r,cmd
Include>%TEMP_DIR%\_temp.scp
DeleteFile>%TEMP_DIR%\_temp.scp
MessageModal>PostData
HTTPRequest>server_addr,,POST,PostData,cmd,,,,
Until>cmd,DONE
every time cmd variable is updated with the new command to be executed as long as a DONE is sent by the external script. Now i have the following two commands to be executed:
cmd=messageModal>hello%CR%let>PostData=r=1
cmd=getScreenRes>X,Y%CR%let>a=X%CR%let>b=Y%CR%messageModal>a%CR%messageModal>b%CR%let>PostData=xpos=%X%&ypos=%Y%
Each cmd will be written to the temp file and executed. Now i am facing a problem to execute these 2 commands in a loop. First commands executes and i can see the message box pop up. But when the second command is written to the _temp.scp(I have checked the file if it has the right command) Include will again execute the first command.
I cant find much help on this. Please let me know if there is any flush that i have to set. I am not able to proceed further because of this.
I am using the following block of code to execute commands in macro scheduler that are sent by an external script.
WriteLn>%TEMP_DIR%\_temp.scp,r,cmd
Include>%TEMP_DIR%\_temp.scp
DeleteFile>%TEMP_DIR%\_temp.scp
MessageModal>PostData
HTTPRequest>server_addr,,POST,PostData,cmd,,,,
Until>cmd,DONE
every time cmd variable is updated with the new command to be executed as long as a DONE is sent by the external script. Now i have the following two commands to be executed:
cmd=messageModal>hello%CR%let>PostData=r=1
cmd=getScreenRes>X,Y%CR%let>a=X%CR%let>b=Y%CR%messageModal>a%CR%messageModal>b%CR%let>PostData=xpos=%X%&ypos=%Y%
Each cmd will be written to the temp file and executed. Now i am facing a problem to execute these 2 commands in a loop. First commands executes and i can see the message box pop up. But when the second command is written to the _temp.scp(I have checked the file if it has the right command) Include will again execute the first command.
I cant find much help on this. Please let me know if there is any flush that i have to set. I am not able to proceed further because of this.