YuChan Posted November 13, 2020 Share Posted November 13, 2020 Hello i have this code : While 1 $chars = FileReadLine($vrFchConf, 1) MsgBox(0, "Char read:", $chars) Wend FileClose($vrFchConf) But a loop don't stop after a last line. Please can you help me to stop a loop when is end line ? THX Link to comment Share on other sites More sharing options...
TheDcoder Posted November 13, 2020 Share Posted November 13, 2020 While 1 $chars = FileReadLine($vrFchConf, 1) If @error Then ExitLoop MsgBox(0, "Char read:", $chars) Wend FileClose($vrFchConf) Read the documentation for FileReadLine EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
YuChan Posted November 13, 2020 Author Share Posted November 13, 2020 Sorry but don't work. I have messsage box every time. Link to comment Share on other sites More sharing options...
YuChan Posted November 13, 2020 Author Share Posted November 13, 2020 expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <array.au3> #Region ### START Koda GUI section ### Form=c:\users\administrateur\documents\bot\interface\general.kxf Global $currentVersion = 400 Global $GUI = GUICreate("DBG" & $currentVersion & "", 595, 539, 191, 126, -1, $WS_EX_TOPMOST) Global $Tab1 = GUICtrlCreateTab(8, 8, 577, 513) Global $TabSheet2 = GUICtrlCreateTabItem("Dofbot G4") Global $journalFile = FileOpen(@ScriptDir & "\dofbotJournal.txt",1) Global $journal = GUICtrlCreateEdit("", 16, 48, 257, 329, BitOR($ES_AUTOVSCROLL,$ES_READONLY,$WS_VSCROLL)) GUISetState(@SW_SHOW) Global $optionDebug = 0 #EndRegion ### END Koda GUI section ### While 1 $chars = FileReadLine($journalFile, 1) If @error Then ExitLoop MsgBox(0, "Char read:", $chars) Wend FileClose($journalFile) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Link to comment Share on other sites More sharing options...
JockoDundee Posted November 13, 2020 Share Posted November 13, 2020 17 minutes ago, YuChan said: Sorry but don't work. I have messsage box every time. So take it out Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
YuChan Posted November 13, 2020 Author Share Posted November 13, 2020 Look my code please. Can you show error ? And i can't close message box window Link to comment Share on other sites More sharing options...
Developers Jos Posted November 13, 2020 Developers Share Posted November 13, 2020 Please start reading the helpfile and try to understand what it is you are coding as your script is reading forever record 1 of file so obviously will never encounter en EOF (thus @error)! Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
GokAy Posted November 13, 2020 Share Posted November 13, 2020 (edited) Hey YuChan, You are trying to read first line over and over again. And getting the messagebox Global $iLine = 1 While 1 $chars = FileReadLine($journalFile) If @error Then ExitLoop ConsoleWrite("Line: " & $iLine & " > " & $chars & @CRLF) ; * See below $iLine += 1 Wend ; * : Replace consolewrite () with what you actually want to do with the read string, as it is you are not doing anything @Jos beat me to it Edit: Open "Output" pane from View menu in SciTe to see console. Would the part I added miss last line? Or error=-1 is set after reading the last line? Edited November 13, 2020 by GokAy Link to comment Share on other sites More sharing options...
TheDcoder Posted November 13, 2020 Share Posted November 13, 2020 @GokAy Good catch, but you forgot to modify the function call to FileReadLine to include $iLine Global $iLine = 1 While 1 $chars = FileReadLine($journalFile, $iLine) If @error Then ExitLoop ConsoleWrite("Line: " & $iLine & " > " & $chars & @CRLF) ; * See below $iLine += 1 Wend ; * : Replace consolewrite () with what you actually want to do with the read string, as it is you are not doing anything EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
YuChan Posted November 13, 2020 Author Share Posted November 13, 2020 Sorry but i not understand. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <array.au3> #Region ### START Koda GUI section ### Form=c:\users\administrateur\documents\bot\interface\general.kxf Global $currentVersion = 400 Global $GUI = GUICreate("DBG" & $currentVersion & "", 595, 539, 191, 126, -1, $WS_EX_TOPMOST) Global $Tab1 = GUICtrlCreateTab(8, 8, 577, 513) Global $TabSheet2 = GUICtrlCreateTabItem("Dofbot G4") Global $journalFile = FileOpen(@ScriptDir & "\dofbotJournal.txt",1) Global $journal = GUICtrlCreateEdit("", 16, 48, 257, 329, BitOR($ES_AUTOVSCROLL,$ES_READONLY,$WS_VSCROLL)) GUISetState(@SW_SHOW) Global $optionDebug = 0 #EndRegion ### END Koda GUI section ### While 1 $chars = FileReadLine($journalFile, 1) If @error Then ExitLoop MsgBox(0, "Char read:", $chars) Wend FileClose($journalFile) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd It's my code. What's i have fail in code for have one loop unlimited ? Link to comment Share on other sites More sharing options...
Developers Jos Posted November 13, 2020 Developers Share Posted November 13, 2020 1 hour ago, TheDcoder said: but you forgot to modify the function call to FileReadLine to include $iLine ... and why would you want to do that in stead of the default "next line" as in that example? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted November 13, 2020 Developers Share Posted November 13, 2020 3 hours ago, GokAy said: Would the part I added miss last line? Or error=-1 is set after reading the last line? Have you tried to get the answer? Spoiler All lines will be shown. @Error is set after the last line is read. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted November 13, 2020 Developers Share Posted November 13, 2020 1 hour ago, YuChan said: It's my code. What's i have fail in code for have one loop unlimited ? Apply what we told you in stead of simply posted the same code again! SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
GokAy Posted November 13, 2020 Share Posted November 13, 2020 (edited) Hey all, @TheDcoder No, I didn't forget to put in $iLine, it was merely for displaying line number for console output. Should have mentioned that though @Jos I had to go out, so could only test it now. So @error is set afterwards, and it is ok. However, I noticed another mistake in YuChan's code. FileOpen with mode 1 (append mode) does not read any lines in my test. Default 0 works (as mentioned in FileReadLine details). Global $journalFile = FileOpen(@ScriptDir & "\dofbotJournal.txt") ; don't use mode 1 Edited November 13, 2020 by GokAy JockoDundee 1 Link to comment Share on other sites More sharing options...
TheDcoder Posted November 13, 2020 Share Posted November 13, 2020 @Jos @GokAy Oops, didn't realize FileReadLine kept track of the last read line by default (it was mentioned in the remarks, which I did not read). In any case, if you are already keeping track of the line no., it is better to explicitly pass it to FileReadLine as well EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
GokAy Posted November 13, 2020 Share Posted November 13, 2020 (edited) @TheDcoder If you need the line number for something, yes. I would remove it altogether after making sure everything is working as intended though. No need for avoidable computation. Edited November 13, 2020 by GokAy TheDcoder 1 Link to comment Share on other sites More sharing options...
JockoDundee Posted November 13, 2020 Share Posted November 13, 2020 @GokAy, minor point but putting Global declarations within loops is probably not the best practice - besides having a (very) slight performance penalty, it causes considerable cognitive dissonance for those of us who come from other environments where such a construct is inconceivable Good catch on the FileOpen mode... Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
GokAy Posted November 13, 2020 Share Posted November 13, 2020 @JockoDundee You are right, OP's code was using globals so I decided to go that way in case it would cause issues with a local declared at the top. Link to comment Share on other sites More sharing options...
YuChan Posted November 14, 2020 Author Share Posted November 14, 2020 (edited) Quote Global $journalFile = FileOpen(@ScriptDir & "\dofbotJournal.txt") ; don't use mode 1 Thx GokAy, problem is solved Edited November 14, 2020 by YuChan 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