Using "contains" inside parenthesis?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chinagreenelvis
Posts: 133
Joined: 19 Oct 2015, 16:21

Using "contains" inside parenthesis?

17 Jul 2017, 01:33

I generally format my code:

Code: Select all

If (condition1) || (condition2 && condition3)
{
  do stuff
}
But this doesn't work when using contains. For example:

Code: Select all

If (condition1) || (condition2 && Var contains Var2, Var3)
{
  don't bother to do stuff because you'll get an illegal character error, apparently AHK thinks the second parenthesis is part of the variable
}
How do I get this to function while still using brackets, which are essential for and/or operations?
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Using "contains" inside parenthesis?

17 Jul 2017, 01:50

Per contains documentation:
The operators "between", "is", "in", and "contains" are not supported in expressions.
You can stack the If statements. Perhaps in this instance, it'll be easier for a gosub routine:

Code: Select all

If (Condition1)
Gosub Stuff
else if (condition2)
{
If var contains Var2, Var3
GoSub Stuff
else
MsgBox condition1 is false and condition2 is true.
}
else
MsgBox Both conditoin1 and condition2 are false.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Using "contains" inside parenthesis?

17 Jul 2017, 01:54

If (condition1) || (condition2 && (InStr(Var,Var2) || InStr(Var, Var3))) Probably nonsense

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Joey5 and 298 guests