This has been a bit of blur for me since the start but I think I should sort it out.
I use a screen capture line as an example:
Say I have read the variable deftolerance from an ini file and so deftolerance = 50
My line is:
FindImagePos>%SCRIPT_DIR%\graphics\%mutegraf%,%SCRIPT_DIR%\screen\export.bmp,%deftolerance%,1,mx,my,mute
or it could be:
FindImagePos>%SCRIPT_DIR%\graphics\%mutegraf%,%SCRIPT_DIR%\screen\export.bmp,deftolerance,1,mx,my,mute
Both of the above work fine. In this case the variable will never be touched or changed while the script is running.
Which is best and if possible why?
This is not a request for support so not urgent. Maybe more of a help for me and others and a topic for discussion.
To %% or not to %%... That is the question...
Moderators: Dorian (MJT support), JRL
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
To %% or not to %%... That is the question...
Phil Pendlebury - Linktree
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
I tend to always use %variable% format with the %.
The two main reasons that I do this are:
1. Log files show the actual value of the variable vs. the variable name. This is extremely useful when troubleshooting.
2. Easy to identify variables in strings and formulas.
The two main reasons that I do this are:
1. Log files show the actual value of the variable vs. the variable name. This is extremely useful when troubleshooting.
2. Easy to identify variables in strings and formulas.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Hi Bob,Bob Hansen wrote:I tend to always use %variable% format with the %.
The two main reasons that I do this are:
1. Log files show the actual value of the variable vs. the variable name. This is extremely useful when troubleshooting.
2. Easy to identify variables in strings and formulas.
That is what I have been doing but I just wondered if it was wrong in any way.
Thanks for that.
Phil Pendlebury - Linktree
When resolving a variable surrounding the variable in percents is never "wrong".
When assigning a variable surrounding the variable in percents is almost always wrong. One exception is when assigning an arrayed variable, the variable used as the array counter will be surrounded by percents. See this thread for a discussion about assigning variables with percents.
Parameters are the values passed to or set by a function. If the function has multiple parameters, they are separated by commas. If a parameter contains a variable and the variable is the entire parameter no percents are needed. The exception is when the system variable "VarExplicit" is set to 1.
If a parameter contains a variable and the parameter contains even one character that is not a part of the variable name, then the variable must be surrounded by percents.
For example:
To summarize, Percents are needed around a variable when:
1) There are characters in a parameter that are not part of the variable.
2) VarExplicit is set to 1.
Percents are NOT needed around a variable when:
1) Assigning a value to the variable.
2) The variable is the parameter.
When assigning a variable surrounding the variable in percents is almost always wrong. One exception is when assigning an arrayed variable, the variable used as the array counter will be surrounded by percents. See this thread for a discussion about assigning variables with percents.
Parameters are the values passed to or set by a function. If the function has multiple parameters, they are separated by commas. If a parameter contains a variable and the variable is the entire parameter no percents are needed. The exception is when the system variable "VarExplicit" is set to 1.
For example:Help for VarExplicit: wrote:Macro Scheduler will look at any parameter to see if it is a variable. If a variable with that name exists, the value assigned to that variable is used, otherwise just that literal value is used. Setting VAREXPLICIT to 1 stops this behaviour and tells Macro Scheduler only to resolve a variable if it is contained within % symbols.
Code: Select all
Let>VarExplicit=0
Let>WinX=100
Let>WinY=100
MouseMove>WinX,WinY
//Or
MouseMove>%WinX%,%WinY%
//Either way is correct since VarExplicit=0
For example:
Code: Select all
Let>VarExplicit=0
Let>FileName1=Test.txt
Let>FileName2=Final.txt
CopyFile>C:\temp\%FileName1%,C:\Data\%FileName2%
1) There are characters in a parameter that are not part of the variable.
2) VarExplicit is set to 1.
Percents are NOT needed around a variable when:
1) Assigning a value to the variable.
2) The variable is the parameter.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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?
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Ahhh there you go.mtettmar wrote:Here's an article I wrote in July:
http://www.mjtnet.com/blog/2008/07/04/u ... -variable/
Phil Pendlebury - Linktree