or I'm doing sth wrong ?
Code: Select all
if var in %foo%
|| var in %bar%
{
MsgBox Won't hit me "if foo not correct"
}
Code: Select all
if var in %foo%
|| var in %bar%
{
MsgBox Won't hit me "if foo not correct"
}
Code: Select all
WinGet, list, List
WinGet, hwnd, ID, A
if hwnd in %list%
msgbox
Sorry my bad.evilC wrote:It's not clear what you are trying to do.
What is the contents of var, foo and bar?
The "if var in" syntax is for checking if something is in a match list, and you do not appear to have provided a list
f var in 1,2,3,5,7,11
According to the docs, if var in %MyItemList% is valid syntax, but I cannot seem to craft a variable MyItemList and have it work.
For example, the following does not work:Code: Select all
WinGet, list, List WinGet, hwnd, ID, A if hwnd in %list% msgbox
Code: Select all
foo:="1,2,3"
bar:="Hwnd,Qt5,Window"
WinGetClass,C,A
if C in %foo%
doFoo()
else if C contains %bar%
doFoo()
Code: Select all
foo:="1,2,3"
bar:="Hwnd,Qt5,Window"
WinGetClass,C,A
if C in %foo% ; Only work if the "if C in %foo%", won't hit doFoo() when "C contains %bar% is true"
|| C contains %bar%
doFoo()
Code: Select all
foo := "1,2,3"
bar := 1
if bar in %foo%
msgbox
Code: Select all
foo = 1,2,3
bar = 1
if bar in %foo%
msgbox
Code: Select all
foo:="1,2,3"
bar:="Hwnd,Qt5,Window"
;ex1
WinGetClass,C,A
if C in %foo%
doFoo()
else if C contains %bar%
doFoo()
Code: Select all
foo:="1,2,3"
bar:="Hwnd,Qt5,Window"
winGetClass,C,A
if(ifIn(C,foo)||ifContains(C,bar))
doFoo()
ifContains(haystack,needle){
if haystack contains %needle%
return 1
return 0
}
ifIn(needle,haystack){
if needle in %haystack%
return 1
return 0
}
I imagine that code does not work because list returns a pseudo-array. list1, list2, list3, etc. You can try this, which in a quick test does produce the msgbox:evilC wrote:It's not clear what you are trying to do.
What is the contents of var, foo and bar?
The "if var in" syntax is for checking if something is in a match list, and you do not appear to have provided a list
f var in 1,2,3,5,7,11
According to the docs, if var in %MyItemList% is valid syntax, but I cannot seem to craft a variable MyItemList and have it work.
For example, the following does not work:Code: Select all
WinGet, list, List WinGet, hwnd, ID, A if hwnd in %list% msgbox
Code: Select all
matchlist:=""
WinGet, list, List
Loop % list
matchlist.=list%A_Index% ","
StringTrimRight, matchlist, matchlist, 1 ; remove the final ","
WinGet, hwnd, ID, A
if hwnd in %matchlist%
MsgBox hi
return
Using function in AHK in not good IMO.Masonjar13 wrote:"If var in" doesn't support or/and. You can, however, append the two to act as an or. Otherwise, you will need a separate statement.You can also create functions for these statements, allowing you to use expression syntax, which is what I do.Code: Select all
foo:="1,2,3" bar:="Hwnd,Qt5,Window" ;ex1 WinGetClass,C,A if C in %foo% doFoo() else if C contains %bar% doFoo()
Code: Select all
foo:="1,2,3" bar:="Hwnd,Qt5,Window" winGetClass,C,A if(ifIn(C,foo)||ifContains(C,bar)) doFoo() ifContains(haystack,needle){ if haystack contains %needle% return 1 return 0 } ifIn(needle,haystack){ if needle in %haystack% return 1 return 0 }
Code: Select all
Loop 100000 ; 100K call
{
WinGetTitle,T,A
if ifIn(T,"qwe,asd,zxc,wer,sdf,xcv,ert,tyu,ghj,bnm")
|| ifContains(T,"Vim")
{}
}
Code: Select all
Loop 100000 ; 100K call
{
WinGetTitle,T,A
if T in qwe,asd,zxc,wer,sdf,xcv,ert,tyu,ghj,bnm
{}
else if T contains Vim
{}
}
Sorry for misunderstand.Exaskryz wrote:I imagine that code does not work because list returns a pseudo-array. list1, list2, list3, etc. You can try this, which in a quick test does produce the msgbox:evilC wrote:It's not clear what you are trying to do.
What is the contents of var, foo and bar?
The "if var in" syntax is for checking if something is in a match list, and you do not appear to have provided a list
f var in 1,2,3,5,7,11
According to the docs, if var in %MyItemList% is valid syntax, but I cannot seem to craft a variable MyItemList and have it work.
For example, the following does not work:Code: Select all
WinGet, list, List WinGet, hwnd, ID, A if hwnd in %list% msgbox
Code: Select all
matchlist:="" WinGet, list, List Loop % list matchlist.=list%A_Index% "," StringTrimRight, matchlist, matchlist, 1 ; remove the final "," WinGet, hwnd, ID, A if hwnd in %matchlist% MsgBox hi return
Code: Select all
foo:="1,2,3"
bar:="Hwnd,Qt5,Window"
WinGetClass,C,A
full:=foo . "," . bar
if C in %full%
doFoo()