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.
Find string in File and show MsgBox (String appears multiple times) Topic is solved
Re: Find string in File and show MsgBox (String appears multiple times) Topic is solved
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%
}
}
Re: Find string in File and show MsgBox (String appears multiple times)
Thanks once again mickeyww,
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Find string in File and show MsgBox (String appears multiple times)
This code will only work once.
Re: Find string in File and show MsgBox (String appears multiple times)
True! You would have to decide when to end the loop, reset pos, etc.
Who is online
Users browsing this forum: No registered users and 241 guests