

This is necessary because the legacy method is used by default by all commands, except where otherwise documented.Ĭomparing variables: Please read the expressions section below for important notes about the different kinds of comparisons, especially about when to use parentheses. In the MsgBox line above, a percent sign and a space is used to change the parameter from legacy to expression mode.

"." A period is used to concatenate (join) two strings. Thus, the following are the expression equivalents of the previous examples: MsgBox % "The value in the variable named Var is ". For example: MsgBox The value in the variable named Var is %Var%.īy contrast, the expression method omits the percent signs around variable names, but encloses literal strings in quotes. The legacy method requires that each variable name be enclosed in percent signs to retrieve its contents. Retrieving the contents of variables: Like the two methods of storing values, there are also two methods for retrieving them: legacy and expression. The empty pair of quotes above should be used only with the colon-equal operator (:=) because if it were used with the equal operator (=), it would store two literal quote-characters inside the variable. You may have guessed from the above that there are two methods to erase the contents of a variable (that is, to make it blank): MyVar = The latter method is preferred by many due to its greater clarity, and because it supports an expression syntax nearly identical to that in many other languages. The following examples are functionally identical to the previous ones: MyNumber := 123ĬopyOfVar := Var Unlike its counterpart in the previous section, percent signs are not used with the := operator. For example: MyNumber = 123ĬopyOfVar = %Var% With the = operator, percent signs are required to retrieve a variable's contents.īy contrast, the expression method uses the colon-equal operator (:=) to store numbers, quoted strings, and other types of expressions. The legacy method uses the equal sign operator (=) to assign unquoted literal strings or variables enclosed in percent signs. Storing values in variables: To store a string or number in a variable, there are two methods: legacy and expression.

See Variables for general explanation and details about how variables work. Variables and Expressions - Definition & Usage | AutoHotkey Variables and Expressions Table of Contents
