mattw112 Posted January 11, 2009 Share Posted January 11, 2009 I tried searching for this but I guess the search engine doesn't like the "@" symbol. Anyway, I have 2 While statements in my code they exit from the loop when an @error = -1 (pretty standard) The problem is that my second while loop never happens because I believe it is still seeing the @Error = -1 from the last while loop. I tried using the SetError command in many different places but that didn't work either. Maybe I am using it wrong? SetError("0") also tried SetError(0) How do I get the @Error back to a non -1 state is there a different command? Thanks, Terry Link to comment Share on other sites More sharing options...
Valuater Posted January 11, 2009 Share Posted January 11, 2009 I do not believe that is the problem, you have to show code for help though 8) Link to comment Share on other sites More sharing options...
FireFox Posted January 11, 2009 Share Posted January 11, 2009 @mattw112 SetError is only used in functions to set the return error flag, like you say : it return generaly -1 Cheers, FireFox. Link to comment Share on other sites More sharing options...
mattw112 Posted January 11, 2009 Author Share Posted January 11, 2009 ok, so how would you set the @error just within code not in a function? Or clear it from it's previous setting? Basically I want to read lines of a file from two different files one after another... So I have 2 while loops back to back and the code is similar to this: While 1 $line = FileReadLine($file1) If @error = -1 Then ExitLoop _DoSomeFunction1() Wend While 1 $line = FileReadLine($file2) If @error = -1 Then ExitLoop _DoSomeFunction2() Wend And the function in the second While loop never gets executed because when the code gets to the @error (in the second while) it exit's the loop. I know it ends here because I've stepped through it. Thanks, Terry Link to comment Share on other sites More sharing options...
FireFox Posted January 11, 2009 Share Posted January 11, 2009 @mattw112 Using : If @error Then will take last error, but if you specify error for the previous function like this : $line = FileReadLine("yourfile.ext",1) If $line = @error and @error = -1 then ;there is error and the return error is -1 EndIf this would work Cheers, FireFox Link to comment Share on other sites More sharing options...
trancexx Posted January 12, 2009 Share Posted January 12, 2009 ok, so how would you set the @error just within code not in a function? Or clear it from it's previous setting? Basically I want to read lines of a file from two different files one after another... So I have 2 while loops back to back and the code is similar to this: While 1 $line = FileReadLine($file1) If @error = -1 Then ExitLoop _DoSomeFunction1() Wend While 1 $line = FileReadLine($file2) If @error = -1 Then ExitLoop _DoSomeFunction2() Wend And the function in the second While loop never gets executed because when the code gets to the @error (in the second while) it exit's the loop. I know it ends here because I've stepped through it. Thanks, Terry@error is set to 0 when entering new function, you don't have to clear anything. If you want to _DoSomeFunction2() after the error = -1 and before you exit the loop then do something like this: While 1 $line = FileReadLine($file2) If @error = -1 Then _DoSomeFunction2() ExitLoop EndIf Wend And if you want to _DoSomeFunction2() regardless of error and exit loop after @error = -1 and after _DoSomeFunction2() then do this: While 1 $line = FileReadLine($file2) $error = @error _DoSomeFunction2() If $error = -1 Then ExitLoop Wend There are at least few more possibilities depending only (I guess) on what you really need. @mattw112 Using : If @error Then will take last error, but if you specify error for the previous function like this : $line = FileReadLine("yourfile.ext",1) If $line = @error and @error = -1 then ;there is error and the return error is -1 EndIf this would work Cheers, FireFoxWoow man!! You are on completely different level. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
FireFox Posted January 12, 2009 Share Posted January 12, 2009 (edited) @trancexx drunk too much the day I posted this Cheers, FireFox. Edited January 12, 2009 by FireFox Link to comment Share on other sites More sharing options...
mattw112 Posted January 13, 2009 Author Share Posted January 13, 2009 trancexx, not sure that will work... These are simple Read lines from file while loops, @Error gets set when the end of the file is reached... My problem is this gets carried over to the next while loop and it thinks the @error was set and exits the loop before it should. The function only occurs after the exitloop statement because if you've reached the end of the file then you can't do the function on empty data. Maybe I'm reading what you wrote wrong though... Again my code is similar to this: While 1 $line = FileReadLine($file1) If @error = -1 Then ExitLoop _DoSomeFunction1() Wend While 1 $line = FileReadLine($file2) If @error = -1 Then ExitLoop _DoSomeFunction2() Wend It seems like I should have an easy way to just say: @Error = "" And zero it out again? Thanks, Terry Link to comment Share on other sites More sharing options...
BrettF Posted January 13, 2009 Share Posted January 13, 2009 I get no problems with this code:Sample:$file1 = FileOpen ("File1.txt", 0) $file2 = FileOpen ("File2.txt", 0) If $file1 = -1 Then MsgBox(0, "Error", "Unable to open file 1.") Exit EndIf If $file2 = -1 Then MsgBox(0, "Error", "Unable to open file 2.") Exit EndIf While 1 $line = FileReadLine($file1) If @error = -1 Then ExitLoop MsgBox (0, "", $line) WEnd MsgBox (0, "Done This Loop!", "Moving to next loop") While 1 $line = FileReadLine($file2) If @error = -1 Then ExitLoop MsgBox (0, "", $line) WEnd MsgBox (0, "Done This Loop Too!", "Both Loops used") FileClose ($file1) FileClose ($file2)File1.txt1 2 3 4 5File2.txt5 4 3 2 1 Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! 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