Flagging Variable From Group

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
scriptor2016
Posts: 862
Joined: 21 Dec 2015, 02:34

Flagging Variable From Group

16 Jul 2022, 01:15

I have a text file which looks like this:

one
two
three
four
five
six
seven
eight
nine
ten


My script will read that text file line-by-line. When the text in the A_LoopReadLine reaches three,six,seven and eventually nine, it should pop up a messagebox - but only for those four numbers.

However though, it works not. Simple syntax error probably, but as usual I'm unable to find the proper way to do it sing the desired variables in a group. Thanks for any help

Code: Select all

Group=
(
three
six
seven
nine
)

Loop, read, C:\MyTextFile.txt

IfInString, A_LoopReadLine, %Group% 
msgbox, %A_LoopReadLine%
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Flagging Variable From Group

16 Jul 2022, 02:47

try contains https://www.autohotkey.com/docs/commands/IfIn.htm

look at third example and make sure to follow it exactly because spaces matter
Rohwedder
Posts: 7656
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Flagging Variable From Group

16 Jul 2022, 02:47

Hallo,
try:

Code: Select all

Group=
(
three
six
seven
nine
)

Loop, read, C:\MyTextFile.txt
	IfInString, Group, %A_LoopReadLine% 
		msgbox, %A_LoopReadLine%
or:

Code: Select all

Group = three,six,seven,nine

Loop, read, C:\MyTextFile.txt
	If A_LoopReadLine in %Group%
		msgbox, %A_LoopReadLine%
scriptor2016
Posts: 862
Joined: 21 Dec 2015, 02:34

Re: Flagging Variable From Group

16 Jul 2022, 02:58

Hi, thanks to both of you guys. Really appreciated :)



I was able to get it going like this:

Code: Select all

Loop, read, C:\MyTextFile.txt

if A_LoopReadLine contains three,six,seven,nine
msgbox, %A_LoopReadLine%
which I suppose is much easier than creating a group.

However, the Group idea still won't work (yet) no matter which approach is tried.

Just a matter of sybntax probably, but the solution above is probably the easiest :)
scriptor2016
Posts: 862
Joined: 21 Dec 2015, 02:34

Re: Flagging Variable From Group

16 Jul 2022, 03:02

ooops, nevermind - just saw Rohwedder's reply as well:

Code: Select all

Group=
(
three
six
seven
nine
)

Loop, read, C:\MyTextFile.txt
	IfInString, Group, %A_LoopReadLine% 
		msgbox, %A_LoopReadLine%


...and it works as well.

Perfect, thanks!!
Rohwedder
Posts: 7656
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Flagging Variable From Group

16 Jul 2022, 03:19

Better use in instead of contains!
Try:

Code: Select all

Group = 3rd,6th,7th,9th
Loop, 99
	Ordinals .= Ordinal(A_Index) ","

Loop, Parse, Ordinals, CSV
	If A_LoopField contains %Group%
		msgbox, %A_LoopField%
		
Ordinal(Num)
{
    Static OrdList := ["st","nd","rd"]
    Return Num (Num ~= "1[1-3]$" Or !(Ord:=OrdList[SubStr(Num, 0)])?"th":Ord)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: GEOVAN and 201 guests