Jump to content

FileReadLine issue


Recommended Posts

Hi, i'm trying to find a certain string(word) in a big text file by using FileReadLine() but i can't loop to read each line from the first to the last one because the first line is 1 and the last is -1 and For...To...Step...Next with Step +1 doesn't work. i hope i made myself clear, the point is to have the line counting.

$open=FileOpen("wordweb5.txt", 0) ; open the text file in read mode
For $i = 1 To -1 Step +1          ; loop to read from the first line to the last
    $read = FileReadLine($open, $i) ; read from the first line to the last
    ToolTip($i,1,1)                  ; show counting
    If StringInStr($read, "europe!") = True Then MsgBox(Default, Default, $read&" found on line "&$i) ;MsgBox when String is found
Next
FileClose($open) ;close filehandle
Exit
Link to comment
Share on other sites

You can use a simple While 1 loop :

$hFile = FileOpen("file.txt")
If $hFile = -1 Then Exit MsgBox(16, "", "error")
$iCount = 0

While 1
    $iCount += 1
    $line = FileReadLine($hFile)
    If @error Then ExitLoop
    
    ToolTip($iCount,1,1)
    If StringInStr($line, "europe!") Then MsgBox(0, "", " ""europe! "" found on line " & $iCount)
WEnd
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...