Pera Posted January 12, 2007 Share Posted January 12, 2007 I have a code that contains the following; [/autoit] Global $file While 1 $file = FileOpen("Filepath\chat.log") $TexttobeRead = $file . . . . . Func DeleteLog() FileClose($file) $file = FileOpen( "Filepath\chat.log", 2) ;to erase the previous content FileClose($file) EndFunc [autoit] For some reason even though chat.log file is being erased by DeleteLog function, I still get an error saying that "Maximum number of lines can be opened is reached". That is not the exact error but its close to that. Pretty much i am getting error that makes me believe that somewhere somehow $file is keep building up, even though the chat.log file is getting erased periodically. Any help would be greatly appreciated. Thanks Link to comment Share on other sites More sharing options...
Developers Jos Posted January 12, 2007 Developers Share Posted January 12, 2007 can you show an actual scriptlet that shows the behaviour ? Sounds to me you are foing more fileOpen() statements than FileClose() statements... 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...
MHz Posted January 12, 2007 Share Posted January 12, 2007 can you show an actual scriptlet that shows the behaviour ?Have a look here http://www.autoitscript.com/forum/index.php?showtopic=39299 Link to comment Share on other sites More sharing options...
Developers Jos Posted January 12, 2007 Developers Share Posted January 12, 2007 (edited) Have a look here http://www.autoitscript.com/forum/index.php?showtopic=39299nah... that was another issue so my guess is that the script is changed and the FileOpen() is now at the wrong spot ... ...but yes... that topic should have been used ... its now very confusing Edited January 12, 2007 by JdeB 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...
Pera Posted January 12, 2007 Author Share Posted January 12, 2007 (edited) Have a look here http://www.autoitscript.com/forum/index.php?showtopic=39299I changed that script since I post. I figured out that the reason why things got messed up in that script because I assign the chat.log to $file at the very beginning and never again. So I moved the assignment "$file = FileOpen(FilePath\chat.log)" Inside the loop. Edited January 12, 2007 by Pera Link to comment Share on other sites More sharing options...
Pera Posted January 12, 2007 Author Share Posted January 12, 2007 (edited) Ok looks like I got it, but not sure I can't try it right now. My script looked like this when the error happened; [/autoit] Global $file While 1 $file = FileOpen("Filepath\chat.log") $TexttobeRead = $file . . . . . Func DeleteLog() FileClose($file) $file = FileOpen( "Filepath\chat.log", 2) ;to erase the previous content FileClose($file) $file = FileOpen( "Filepath\chat.log", 0) ;I believe this is the reason?? EndFunc [autoit] So I think what happened is I opened the file once in the loop, closed it in the DeleteLog() func, opened it, and opened it again in the loop. So eventually I kept opening the file over and ovr without closing it. I apoligize I post a lot in the last couple of days but I just start using AutoIt recently (3-4 days ago) and still trying to figure things out. Thanks! Edited January 12, 2007 by Pera Link to comment Share on other sites More sharing options...
MHz Posted January 12, 2007 Share Posted January 12, 2007 The question is...do you need to have a handle to the file or just use FileRead to read the whole file and just use FileDelete on it to clear as the program would recreate the log file again? Link to comment Share on other sites More sharing options...
Pera Posted January 12, 2007 Author Share Posted January 12, 2007 (edited) The question is...do you need to have a handle to the file or just use FileRead to read the whole file and just use FileDelete on it to clear as the program would recreate the log file again?Hmm... I think you are right I could just FileRead() and when my requirements are met I could FileDelete(). But wouldn't the script error out if it tried to read the chat.log again before the program creates it?Edit: I misread your post Edited January 12, 2007 by Pera Link to comment Share on other sites More sharing options...
MHz Posted January 12, 2007 Share Posted January 12, 2007 My thoughts are that FileOpen and FileClose are not needed if you just want to use FileRead to read the whole file once and a while. FileOpen is useful when you are constantly reading or writing to a file by using a handle but you use adequate sleeps that using a handle is perhaps not a speed issue so it maybe easier to not use FileOpen/FileClose and the handle they open and close? Link to comment Share on other sites More sharing options...
Pera Posted January 12, 2007 Author Share Posted January 12, 2007 My thoughts are that FileOpen and FileClose are not needed if you just want to use FileRead to read the whole file once and a while. FileOpen is useful when you are constantly reading or writing to a file by using a handle but you use adequate sleeps that using a handle is perhaps not a speed issue so it maybe easier to not use FileOpen/FileClose and the handle they open and close? Alright then, how about something like this; expandcollapse popup[/autoit] While 1 Mouseclick("Right", 725, 480, 1) $TexttobeRead = FileRead("FilePath\chat.log") ;MsgBox(0, "Outside the BG", $TexttobeRead, 10) If StringInStr($TexttobeRead, "entering") Then ;MsgBox(0, "Inside the BG", "We are Inside the BG", 10) Sleep(Random(750, 900)) Send("{LCTRL 2}") Send("{g}") InsideBG() DeleteLog() EndIf ;MsgBox(0, "Waiting to Enter the BG","", 10) Sleep(Random(300, 450)) Wend Func DeleteLog() FileDelete("FilePath\chat.log") EndFunc Func InsideBG() Do Send("{TAB}") Sleep(random(2000, 4000)) Send("{TAB}") Sleep(random(2000, 4000)) Send("{TAB}") Sleep(random(2000, 4000)) Send("{TAB}") Sleep(random(2000, 4000)) $InsideBGCheck = FileRead("FilePath\chat.log") ;MsgBox(0, "Inside BG Function", $InsideBGCheck, 10) Sleep(Random(3000, 6000)) Send("{LCTRL 2}") Send("{g}") Until StringInStr($InsideBGCheck, "ended") EndFunc [autoit] Link to comment Share on other sites More sharing options...
MHz Posted January 12, 2007 Share Posted January 12, 2007 Looks worth trying. Tip: Don't set clicks parameter for MouseClick as 1 is default setting and is a optional parameter. Link to comment Share on other sites More sharing options...
Pera Posted January 12, 2007 Author Share Posted January 12, 2007 Looks worth trying. Tip: Don't set clicks parameter for MouseClick as 1 is default setting and is a optional parameter.I know its a very ugly looking code .thanks for the tip. 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