amf Posted April 2, 2010 Share Posted April 2, 2010 Hi I have used a code snippet from the help file and added one line (marked with -->) and now it runs as an endless loop... --------------------------------------------------- $file = FileOpen("Test.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) --> MsgBox(0,"Value", @error) If @error = -1 Then ExitLoop MsgBox(0, "Line read:", $line) Wend FileClose($file) --------------------------------------------------- Any ideas why this code runs an endless loop? Link to comment Share on other sites More sharing options...
FuryCell Posted April 2, 2010 Share Posted April 2, 2010 You are getting the @error for msgbox instead of the one you want. Move the msgbox after the @error check. HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
crashdemons Posted April 2, 2010 Share Posted April 2, 2010 (edited) As FuryCell stated. Here's something from the Help File: When entering a function @error is set to 0. Unless SetError() is called, then @error will remain 0 after the function has ended. This means that in order for @error to be set after a function, it must be explicitly set. This also means you may need to backup the status of @error in a variable if you are testing it in a While-WEnd loop. Applied to your example: The function FileReadLine() is entered, @error is reset to 0, then possibly set by the functionThe function MsgBox() is entered (with the previous @error as part of the parameter), @error is reset to 0, then possibly set by the function.You checked the value of @error (which was reset by MsgBox() ) in "If @error = -1 Then ExitLoop" You could set a variable like $err equal to @error before calling MsgBox, and use $err instead of @error, as one possible solution. $file = FileOpen("Test.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) $err=@error MsgBox(0,"Value", $err) If $err = -1 Then ExitLoop MsgBox(0, "Line read:", $line) Wend FileClose($file) Edited April 2, 2010 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
amf Posted April 2, 2010 Author Share Posted April 2, 2010 Hi Thanks for the fast reply. Do you mean that the first msgbox causes an error? The pupose of that msgbox was to check if the line was at the last line in the file but when it reaches tha last line it just continues. Link to comment Share on other sites More sharing options...
amf Posted April 2, 2010 Author Share Posted April 2, 2010 Ahh now I got it... thanks very much, both Link to comment Share on other sites More sharing options...
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