![]() ![]() They can be used to make a script more readable as in these examples: CaseSensitive := false The words true and false are built-in variables containing 1 and 0. To take advantage of this, the shorthand statement if Done can be used to check whether the variable Done is true or false. Operators such as NOT/AND/OR/>/=/ 5 or FoundItĪs hinted above, a variable can be used to hold a false value simply by making it blank or assigning 0 to it. Similarly, the expression if not ItemCount would yield the opposite result. For example, the statement if ItemCount would be false only if ItemCount is blank or 0. For example: NetPrice := Price * (1 - Discount/100)īoolean values: When an expression is required to evaluate to true or false (such as an IF-statement), a blank or zero result is considered false and all other results are considered true. Storing the result of an expression: To assign a result to a variable, use the := operator. On a related note, any invalid expression such as (x +* 3) yields an empty string. Thus, to check if a variable is blank with a traditional-if, use = or != with nothing on the right side as in this example: if Var =. For example, the statement if MyVar = "" is true only if MyVar contains an actual pair of quotes. However, in a traditional-if, a pair of empty quotes is treated literally. For example, the statement if (MyVar != "") would be true if MyVar is not blank. Note: There are several types of If Statement which look like expressions but are not.Įmpty strings: To specify an empty string in an expression, use an empty pair of quotes. To include an actual quote-character inside a literal string, specify two consecutive quotes as shown twice in this example: "She said, ""An apple a day. In the example above, "Blue" appears in quotes because it is a literal string. MsgBox The setting is too high or the wrong color is present. For example: if (CurrentSetting > 100 or FoundColor != "Blue") Consequently, literal strings must be enclosed in double quotes to distinguish them from variables. Variable names in an expression are not enclosed in percent signs (except for pseudo-arrays and other double references). See Expressions for a structured overview and further explanation.Įxpressions are used to perform one or more operations upon a series of variables, literal strings, and/or literal numbers. ![]() 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 := operator because if it were used with the = 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 ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |