Инструменты пользователя

Инструменты сайта


en:documentation:expressions

Expressions

Expressions are used in conditions. Starting with version 2.0.10, calculated expressions can also be used in all parameters of Autorun commands.

For use in command parameters, the parameter must be in quotation marks and immediately before them there was a «%» sign. In this case, the text will be treated as a calculated expression. For example:

Set Delay 500
Sleep %"1000 + %Delay%"
# result = 1500.

Inside quotes for text constants, as elsewhere, you can use quotes of a different type:

StrLen var %'"String_" & 1' 
# var => String_1

Although text constants that not wrapped in quotation marks can be used in expressions, this option is left for compatibility purposes only. It is highly recommended that you use quotation marks everywhere. This will significantly reduce the number of possible errors.

Arithmetic operations, the concatenation operation «&» of strings, and logical operations can be used in expressions.

For numeric comparison operator can be one of: =, <>, >, <, >=, ⇐. For string comparison only = and <> allowed, comparison is case insensitive. Allowed brackets and operators AND and OR. If both expressions are numeric, then numeric comparison used.

If both expressions are numeric, a numeric comparison is used. The following operators can be used: =, <>, >, <, >=, ⇐. For string comparisons, only = and <> are allowed, the comparison is case-insensitive.

Brackets and AND, OR, and NOT operators are also allowed. True/False keywords are allowed, which are equivalent to the strings «1»/«0», respectively.

The priority of operations, from highest to lowest:

NOT
* /
+ -
&
< > <= >= = <> 
AND OR

Using commands in expressions

It is possible to use any Autorun commands in expressions, but it makes sense to use those that return a result.

To use a command as a function in an expression, it must be written using brackets and a comma as a parameter separator. The first parameter (variable name for the return value) is not used in this case. If you need to use the switches, you need to pass them in the first parameter, in quotation marks separated by a space, the parameter text should begin with the character «~». In general, the entry looks like this:

CommandName(["~/S1 /S2 .. /SN",] Param1, Param2, .. , ParamN)

Example:

Set zz "AbCdEfxQWERTY" 
MsgBox %"StrPos('~/S', %zz%, 'x')" "Case-sens" 
# => 7

You can use nested commands in expressions:

Set zz "  abcdefgh" 
MsgBox %"StrLeft(StrTrim(%zz%), 3) & '-' & StrPos(%zz%, 'd') & '-' & (StrPos('123456789', '5'))" "Expr" 
# => abc-6-5 

If environment variables are expanded in the command parameters (see command descriptions), then you can write the variable along with the rest of the text inside the quotation marks. In other cases, you need to use concatenation of the variable with the text:

# environment variables are expanding in the command's parameter
FileExist("%COMMANDER_PATH%\NoClose.exe")
# environment variables are not expanding in the command's parameter
StrLen(%COMMANDER_PATH% & "\NoClose.exe")
en/documentation/expressions.txt · Последние изменения: 2020/04/24 16:29 — loopback

Инструменты страницы