Jump to content

If-Statement in Readline-Loop -> infinite loop


Recommended Posts

Hi,

I just wrote some lines of code where I wanted to scan for specific lines using RegExp.

It looks like this:

$file = FileOpen(@SystemDir & "\drivers\etc\hosts", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(16, "Error", "You may have insufficient rights on this user account or some files are missing. The patch cannot be applied!")
    Exit
EndIf

; Check if lines are already in host-file
While 1
    $line = FileReadLine($file)
    If StringRegExp ( $line , ".*cod2update.?\.activision\.com.*", 0) = 1 Then
        MsgBox(64, "Information", "The patch already has been applied!")
        Exit
    ElseIf @error = -1 Then
        ExitLoop
    EndIf
Wend

But when I use an If-Statement within the while function the script seems not to be able to set @error to -1 when reaching the EOF. I already added a msg box within that while loop to see what's happening. When removing the if-stament everything works fine. Is there anyhing I forgot?

Cheers

Link to comment
Share on other sites

Welcome to the forums.

But when I use an If-Statement within the while function the script seems not to be able to set @error to -1 when reaching the EOF. I already added a msg box within that while loop to see what's happening. When removing the if-stament everything works fine. Is there anyhing I forgot?

FileReadLine is properly setting @error to -1 at EOF, but you're immediately resetting it by calling StringRegExp. (The only possible values for that mode are 0 and 2)

Try this instead:

; Check if lines are already in host-file
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    If StringRegExp($line , ".*cod2update.?\.activision\.com.*", 0) = 1 Then
        MsgBox(64, "Information", "The patch already has been applied!")
        Exit
    EndIf
Wend

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

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...