Jump to content
Sign in to follow this  
zielke

If-Statement in Readline-Loop -> infinite loop

Recommended Posts

zielke

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

Share this post


Link to post
Share on other sites
Skruge

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]

Share this post


Link to post
Share on other sites
zielke

Allright! Now I see what I've done wrong. I'll use the second example since it's much shorter than my code. Thx for helping me out :-)

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.