Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Logical AND condition in an IF clause?


  • Please log in to reply
4 replies to this topic
balaji
  • Members
  • 17 posts
  • Last active: Aug 17 2015 09:30 AM
  • Joined: 08 Jun 2007
Hi folks,

I've probably been staring at the code for too long and missing the obvious answer, but here goes:

I wrote the following function to check if some applications are running:

CheckApps(){

;Now get all process PIDs and check if all three apps are running
global IMClient
global TwitClient
global IRCClient

Process,Exist,%IMClient%
IMPID = %ErrorLevel%
Process,Exist,%TwitClient%
TwitPID = %ErrorLevel%
Process,Exist,%IRCClient%
IRCPID = %ErrorLevel%

If %IMPID%<>0 && %TwitPID%<>0 && %IRCPID% <> 0
{
	;Everything's running. What are we still doing here?
	MsgBox, 4096, , Everything is fine.
	} else {
	StartApps()
}

;CheckApps() ends here
}

My (possibly) muddled thinking is that :

"Only if all 3 variables are non-zero, the MsgBox will appear. Else the StartApps() function is called"

That isn't quite working though - even if one app is running, the message box pops up.

Could someone help me figure out what I'm doing wrong? Many thanks!

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
Add ()s
(%IMPID%<>0) && (%TwitPID%<>0) && (%IRCPID% <> 0)

Edit: in some cases you should use (IMPID <> 0) or ("%IMPID%"<>0) or (IMPID<>"text") depending on what you want to compare, value, contents of var or literal text etc, read docs

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
If ( IMPID  && TwitPID && IRCPID )


balaji
  • Members
  • 17 posts
  • Last active: Aug 17 2015 09:30 AM
  • Joined: 08 Jun 2007

Add ()s

(%IMPID%<>0) && (%TwitPID%<>0) && (%IRCPID% <> 0)

Edit: in some cases you should use (IMPID <> 0) or ("%IMPID%"<>0) or (IMPID<>"text") depending on what you want to compare, value, contents of var or literal text etc, read docs


HugoV - thank you for the tip on the () brackets. Once I added those, the script worked as expected.

I did look at the documentation on using the AND clause, but it was very brief and didn't talk about the importance of using the () brackets.

If ( IMPID  && TwitPID && IRCPID )


SKAN - I tried this, but for some reason it failed to trigger.

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
This should help:
<!-- m -->http://www.autohotke... ... ession.htm<!-- m -->