Page 1 of 1

Using "contains" inside parenthesis?

Posted: 17 Jul 2017, 01:33
by chinagreenelvis
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?

Re: Using "contains" inside parenthesis?

Posted: 17 Jul 2017, 01:50
by Exaskryz
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.

Re: Using "contains" inside parenthesis?

Posted: 17 Jul 2017, 01:54
by BoBo
If (condition1) || (condition2 && (InStr(Var,Var2) || InStr(Var, Var3))) Probably nonsense