Find string in File and show MsgBox (String appears multiple times) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
YN2003
Posts: 8
Joined: 26 Mar 2021, 14:53

Find string in File and show MsgBox (String appears multiple times)

11 Apr 2021, 15:57

Hello,
I'm trying to make a script which constantly looks for a string in the given file using Fileread, and Sends MsgBox when the string is found. But the problem is that the string appears multiple times in the file, I want it to send MsgBox each time the string appears.

For example,
1. [12:31] EventX
2. [13:29] EventX
3. [01:20] EventX
Whenever 'EventX' is found, a MsgBox is to be shown, (1 MsgBox for each string)

I tried creating one using loop function, but it was a complete failure since it kept detecting the same string again and again, I think it could be possible with Searching the string in 'last 10 lines' of the file,

Thanks for help mickeyww and everyone.
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Find string in File and show MsgBox (String appears multiple times)  Topic is solved

11 Apr 2021, 16:20

Code: Select all

file := A_ScriptDir "\test.txt", pos := 0
Loop {
 Sleep, 1000
 If !FileExist(file)
  Continue
 FileRead, ttext, %file%
 If search := InStr(ttext, "EventX",, pos + 1) {
  pos := search
  MsgBox, 64, Found text, Position = %pos%
 }
}
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Find string in File and show MsgBox (String appears multiple times)

11 Apr 2021, 18:13

True! You would have to decide when to end the loop, reset pos, etc.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 241 guests