if Var in MatchList not working with array

Get help with using AutoHotkey and its commands and hotkeys
dsewq1LYJ
Posts: 114
Joined: 26 Aug 2014, 23:21

if Var in MatchList not working with array

05 Apr 2017, 12:35

Codes explain anything.

Ref:
https://autohotkey.com/docs/commands/IfIn.htm

Code: Select all

ABC := ["foo", "bar", "baz"]
A := "foo"
if A in %ABC%
{
    Tooltip % "foo - " 
}
; OR
if A in ABC
{
    Tooltip % "foo - " 
}
; BUT
if A in foo,bar,baz
{
    Tooltip % "foo - " 
}
A_AhkUser
Posts: 1076
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: if Var in MatchList not working with array

05 Apr 2017, 12:55

Code: Select all

if Var in MatchList
if Var not in MatchList

if Var contains MatchList
if Var not contains MatchList
documentation says about MatchList:
A comma-separated list of strings
and also:
The operators "between", "is", "in", and "contains" are not supported in expressions.

Code: Select all

x := "bar"
var := "foo," . x . ",baz"

if x in %var%
{
    Tooltip % "foo - " 
}

EDIT:
Here two solutions using arrays:

Code: Select all

A := {"foo": 1,"bar": 2, "baz": 3}

if (A.HasKey("bar"))
{
    Tooltip % "foo - " 
}
or:

Code: Select all

Loop % (A:=["foo", "bar", "baz"]).MaxIndex()
{
if (A[a_index] == "bar")
{
MsgBox, test
}
}
User avatar
jNizM
Posts: 2560
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: if Var in MatchList not working with array

06 Apr 2017, 01:17

Or this: HasVal.ahk (GitHub)
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1909) x64 | [GitHub] Profile
Donations are appreciated if I could help you
MaxAstro
Posts: 552
Joined: 05 Oct 2016, 13:00

Re: if Var in MatchList not working with array

06 Apr 2017, 09:51

And if that's not enough possible solutions, you could also use a for-loop. :)

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], BushMange, CEA6597, VACO BenQ, w0z and 185 guests