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

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


en:autorun:documentation:expressions

Expressions

Arithmetic operations, «&» string concatenation and logical operations can be used in expressions.

Operators can be used: =, <>, >, <, >=, <=.

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

Internal Autorun variables and existing environment variables can be used.

Internal Autorun commands and user defined functions can be used. If the command does not return a value, then its «result» will be an empty string in the expression.

Priority of execution of operations in descending order:

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

Example:

Percent = i * (count / 100)
InRange = i > 1 and i < 1

Arithmetic operations

When adding, subtracting, multiplying and dividing, if both expressions are numeric (or both strings are converted to numbers), operations on numbers are performed.

If one or both of the values ​​is a string that is not converted to a number, the value of that string is treated as 0.

MsgBox(1 + 5)         # --> 6
MsgBox("1" + "5")     # --> 6
MsgBox("" + 5)        # --> 5
MsgBox("abc" + "cde") # --> 0

Concatenation

This operation returns a string containing the concatenated string representations of the values.

MsgBox(1 & 5)         # --> "15"
MsgBox("1" & 5)       # --> "15"
MsgBox("" & 5)        # --> "5"
MsgBox("abc" & "cde") # --> "abccde"

Value Comparison

When comparing, if both expressions are numeric (or both strings are converted to numbers), a numeric comparison is used.

If a number is compared with a string, then it is performed according to the following rules:

  • if one of the strings is converted to a number, and the second is empty, then its value is considered as 0
  • if one of the strings is converted to a number, and the second is non-empty, then the result of the comparison will be False
  • if none of the strings is converted to a number, a string comparison is performed

For string comparisons, only = and <> are allowed, and the comparison is case-insensitive. For case-sensitive and lexigraphic string comparisons, use the StrCompare function.

Examples:

a = 5
MsgBox(a = 5)         # --> 1
MsgBox(a = "5")       # --> 1
MsgBox("" = False)    # --> 1
MsgBox("abc" = "cde") # --> 0
MsgBox("abc" = 1.5)   # --> 0

Boolean operations

When using the AND, OR, and NOT logical operators, the rules are as follows:

  • values ​​1 and 0 are treated as True and False;
  • if the string is cast to a number, then 0 is treated as False, and a non-zero value — as True;
  • if the string is not cast to a number, then an empty string is treated as False, and a non-empty — as True.
a = 5
MsgBox(1 and 2)         # --> 1
MsgBox(1 and 0)         # --> 0
MsgBox(1 and "")        # --> 0
MsgBox(1 and "c")       # --> 1
MsgBox("" or True)      # --> 1
MsgBox("abc" and "cde") # --> 1
MsgBox(not 1)           # --> 0

Expressions in Command notation

To use expressions in parameters in command notation, the parameter must be in quotation marks and immediately preceded by the «%» sign. In this case, the text will be treated as a calculated expression. For example:

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

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

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

When using LegacyExpressions directive, unquoted text constants can be used in expressions, but this option is left for initial compatibility only. It is highly recommended to rewrite the code and use quotes everywhere. This will significantly reduce the number of possible errors.

Using Commands and Functions 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, it must be written using parentheses and a comma as the parameter separator. The first parameter (the variable name for the return value) is not used in this case. Some commands are adapted for use as a function (eg StrPos, StrReplace) and do not require passing switches. For other commands, when using them, switches must be passed in the first parameter in quotation marks separated by a space, the parameter text must begin with the «~» character. In general, the entry looks like this:

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

An example of a functional notation:

zz = "AbXCdEfxQWERXTY"
MsgBox(StrPos(zz, 'x', 1, 1, 1), "Case-sens")
# => 8

Command notation example:

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

You can use nested commands in expressions:

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

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

# environment variables are expanded in the command parameter
FileExist("%COMMANDER_PATH%\NoClose.exe")
# environment variables in command parameter are not expanded
StrLen(%COMMANDER_PATH% & "\NoClose.exe")
en/autorun/documentation/expressions.txt · Последнее изменение: 2022/11/01 12:59 — loopback

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki