If, and statement

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
RussF
Posts: 1237
Joined: 05 Aug 2021, 06:36

Re: If, and statement

Post by RussF » 23 May 2022, 11:48

boiler wrote:
23 May 2022, 11:43
I believe some things are in there twice because it's two groupings of a series of "and"s that are separated by an "or". And it is desired that that part be true in either of the "or" segments. So I think it's actually meant to be in there twice for good reason. The things you took out of one side probably need to be true in that other side as well. To show the grouping with parentheses:

Code: Select all

if  (!errorlevel & winexist("ahk_exe this") && winexist("ahk_exe thisb") && aaa =1) or (!errorlevel && winexist("ahk_exe check2") && winexist("ahk_exe check2") && aaa=1)
(well, actually, the check2 part could come out, but I can see why !errorlevel is in there twice)
Yes, but notice my extra set of parens surrounding the second group. Since errorlevel and aaa are tested the same on both sides of the "or" with an "and" condition, it can be enclosed in it's own paren group seperated from the rest with an "and".

BTW, you missed an "&" also. :D

Russ

RussF
Posts: 1237
Joined: 05 Aug 2021, 06:36

Re: If, and statement

Post by RussF » 23 May 2022, 11:52

True about order of precedence, but adding parens (at least for me) REALLY helps visualize the logic better.

Russ

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: If, and statement

Post by boiler » 23 May 2022, 11:58

RussF wrote:
23 May 2022, 11:52
True about order of precedence, but adding parens (at least for me) REALLY helps visualize the logic better.

Russ
I agree with that.

TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: If, and statement

Post by TrebleTA » 24 May 2022, 08:42

Thank you that was a big help

TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: If, and statement

Post by TrebleTA » 24 May 2022, 09:10

Would this be correct

Code: Select all

If (!ErrorLevel and lorupro=0 and FileExist("C:\Program Files (x86)\my files\temp\temp.exe")) 

User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: If, and statement

Post by WalkerOfTheDay » 24 May 2022, 09:14

TrebleTA wrote:
24 May 2022, 09:10
Would this be correct

Code: Select all

If (!ErrorLevel and lorupro=0 and FileExist("C:\Program Files (x86)\my files\temp\temp.exe")) 
Just try it out ?

Code: Select all

lorupro := 0

If (!ErrorLevel and lorupro=0 and FileExist("C:\Program Files (x86)\my files\temp\temp.exe")) 
	MsgBox, Yes
else
	MsgBox, No

TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: If, and statement

Post by TrebleTA » 24 May 2022, 09:30

I have tried it just checking it was the correct way.

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: If, and statement

Post by boiler » 24 May 2022, 09:35

Yes, that is correct. As a reminder, if you want to use the shorthand for and, it is && -- not &.

Post Reply

Return to “Ask for Help (v1)”