Code: Select all
if %A_DDDD%<>Saturday
MsgBox Today is not Saturday
else
MsgBox Today is Saturday
Code: Select all
if %A_DDDD%<>Saturday
MsgBox Today is not Saturday
else
MsgBox Today is Saturday
Code: Select all
If (A_DDDD = "Saturday")
MsgBox Today is Saturday
Else MsgBox Today is not Saturday
Thank you. Removing the percent signs has solved the problem. Apparently Autohotkey treats variables in the If expressions differently when these variables are enclosed by percent signs.mikeyww wrote: ↑26 Nov 2022, 14:50Use expressions.
Explained: IfCode: Select all
If (A_DDDD = "Saturday") MsgBox Today is Saturday Else MsgBox Today is not Saturday
Code: Select all
a = r
r = 5
MsgBox,, Expression a , % a
MsgBox,, Expression `%a`%, % %a%
If a variable is enclosed in percent signs within an expression (e.g. %Var%), whatever that variable contains is assumed to be the name or partial name of another variable (if there is no such variable, %Var% resolves to a blank string).
Code: Select all
if (A_DDDD<>"Wednesday" or "Saturday")
Code: Select all
If ((A_DDDD != "Wednesday") AND (A_DDDD != "Saturday"))
MsgBox, Not!
Code: Select all
expression1 := A_DDDD != "Wednesday"
expression2 := A_DDDD != "Saturday"
If (expression1 AND expression2)
MsgBox, Not!
Code: Select all
expression1 := A_DDDD != "Wednesday"
expression2 := "Saturday" ; Always true (in "If") because this string is neither null nor zero
If expression2
MsgBox, Expression2 is true
If (expression1 OR expression2) ; Always true if one expression is always true
MsgBox, At least one expression is true
Thank you very much for the detailed explanations and useful information. I understand now that such operators as AND and OR operate on expressions rather than directly on variables. The variables expression1 and expression2 in your scripts are treated as expressions rather than as variables because they are defined as expressions.mikeyww wrote: ↑27 Nov 2022, 10:25You are using or as you would use it in English, but or is actually a logical operator that is used on one pair of expressions at a time. Each pair of expressions must be intact, though there is an order of precedence that is also used (explained in documentation).
The middle parentheses are not necessary here, but they illustrate the point that AND and OR operate upon one pair of expressions. This type of operator is called a binary operator, because it has exactly two operands. = and != are also binary operators. Thus, the script above shows three operations: two !=, followed by one AND that uses the results of the first two.Code: Select all
If ((A_DDDD != "Wednesday") AND (A_DDDD != "Saturday")) MsgBox, Not!
Explained: OR
Code: Select all
expression1 := A_DDDD != "Wednesday" expression2 := A_DDDD != "Saturday" If (expression1 AND expression2) MsgBox, Not!
Code: Select all
expression1 := A_DDDD != "Wednesday" expression2 := "Saturday" ; Always true (in "If") because this string is neither null nor zero If expression2 MsgBox, Expression2 is true If (expression1 OR expression2) ; Always true if one expression is always true MsgBox, At least one expression is true
Code: Select all
If ((A_DDDD != "Wednesday") AND (A_DDDD != "Saturday"))
MsgBox, Not!
Code: Select all
If !Instr("Wednesday" "Saturday", A_DDDD)
MsgBox, Not!
Code: Select all
If A_WDay in 4,7
MsgBox, Day!
Else MsgBox, Not!