zielke Posted July 22, 2008 Posted July 22, 2008 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
Skruge Posted July 22, 2008 Posted July 22, 2008 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]
zielke Posted July 22, 2008 Author Posted July 22, 2008 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 :-)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now