Page 1 of 1

If and or statements

Posted: 02 Apr 2019, 13:36
by Vh_
Hi, can someone please review this and tell me why I am not getting "I'm an error" regardless of if I have a matching OR (ABC or XYZ)?

Thanks,
Vh_

Code: Select all

Number = 123
Identifier = 123
Code = CAB ;result should be  "not an error"?


if (SSN = Account) && (Code != "ABC" or Code != "XYZ")
	Msgbox, i'm an error
else
	msgbox, not an error.

Re: If and or statements

Posted: 02 Apr 2019, 13:48
by sinkfaze
I copied and ran your code as is, I got i'm an error.

Re: If and or statements

Posted: 02 Apr 2019, 13:50
by Vh_
sinkfaze wrote:
02 Apr 2019, 13:48
I copied and ran your code as is, I got i'm an error.
I misquoted myself! Edited original post. It should be opposite the result you got.

Re: If and or statements  Topic is solved

Posted: 02 Apr 2019, 13:54
by Vh_
phaleth on #ahk IRC helped me figure this out! Thanks!

Code: Select all

Number = 123
Identifier = 123
Code = ABC ;result should be  "not an error"?


if (SSN = Account) && (Code != "ABC" && Code != "XYZ")
	Msgbox, i'm an error
else
	msgbox, not an error.

Re: If and or statements

Posted: 02 Apr 2019, 13:57
by sinkfaze
Well that's much easier to solve.

(Code != "ABC" or Code != "XYZ")

There is literally no value for Code which will cause this statement to evaluate as true. Perhaps you meant to evaluate with and?

(Code != "ABC" and Code != "XYZ")