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

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


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

Использование команд в выражениях

В выражениях возможно использование любых команд Autorun, но смысл имеет использование тех, которые возвращают результат.

Для использования команды в качестве функции в выражении, она должна быть записана с использованием скобок и запятой в качестве разделителя параметров. Первый параметр (имя переменной для возвращаемого значения) в этом случае не используется. Если нужно использовать переключатели, их нужно передавать в первом параметре, в кавычках через пробел, текст параметра должен начинаться с символа «~». В общем виде запись выглядит так:

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

Пример:

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

В выражениях можно использовать вложенные команды:

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

Variables are always expanding in the expressions. If you assume that variable value can conatin spaces, wrap expression in quotes. Example:

If ("%var_with_spaces%" = "value") Then

Also, some special functions can be used in comparison. In this case comparison limited to only one function.

If [Not] Function1 <parameters> Then
  ...
ElseIf [Not] Function2 <parameters> Then
  ...
Else
  ...
EndIf

It's allowed to use both expressions and function in one condition (but in different branches).

en/documentation/expressions.1586278431.txt.gz · Последнее изменение: 2020/04/07 19:53 — loopback

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki