Syed23 5 Report post Posted March 29, 2012 (edited) Hi everyone, i have a doubt one looping concept! For example i am using any while..wend or do..until loop.... and i want to make sure due to some error the loop does not struck. For example i had a situation where i wanted to read the entire log file from the location "c:windowstempdeploymentlogssample.log". For my unit testing i renamed that log file as a different one tried for read the lines but it got strucked and it was looping some where. i was unable to find where the code got strucked some one have any suggestion for handling those kind of situation with any error handling option ? Example script: #RequireAdmin $ZTIFile = FileOpen(@WindowsDir & "TempDeploymentLogsZTIApplications.log", 0) If $ZTIFile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileRea1dLine($ZTIFile) If @error = -1 Then ExitLoop If StringInStr($line, "unexpected") And StringInStr($line, "Application Check for Domain connection returned an unexpected return code") = 0 Then MsgBox(0, "", "ERROR = " & $line) $H += 1 EndIf ;Sleep(50) ; to delay the speed of process of which can consume the usage of CPU WEnd Edited March 29, 2012 by Syed23 Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font] Share this post Link to post Share on other sites
qsek 16 Report post Posted March 29, 2012 (edited) did you get an error or did the script just exit?Why not use the consolewrite function to output the content of $line, so you can see what the script reads.also "FileRea1dLine" is a typo right?and did you think of what the script does when @error = 1 ?read the helpfile for FileReadLine under return value Edited March 29, 2012 by qsek Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite Share this post Link to post Share on other sites
Syed23 5 Report post Posted March 29, 2012 did you get an error or did the script just exit?Why not use the consolewrite function to output the content of $line, so you can see what the script reads.also "FileRea1dLine" is a typo right?i did not get any error message the code hanged just as it is...actually that is part of my 1500 line code. i have a GUI where the test results will be shown instead of msgbox.yes you are correct that's typo FileRea1dLine" sorry for that.. Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font] Share this post Link to post Share on other sites
kylomas 408 Report post Posted March 29, 2012 Syed23, If you do not see the message box in the reproducer that you posted you are reading through the file and at EOF going to whatever follows the loop. You might do as qsek suggested and add some diagnostic consolewrites in your FULL script. Start with obvious stuff like "at function so an so..." and whinnow the problem down to the section you are having a problem with. Good Luck, kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Share this post Link to post Share on other sites
Syed23 5 Report post Posted April 2, 2012 did you get an error or did the script just exit?Why not use the consolewrite function to output the content of $line, so you can see what the script reads.also "FileRea1dLine" is a typo right?and did you think of what the script does when @error = 1 ?read the helpfile for FileReadLine under return valueThanks for the suggestion. But i don't think this helps me out bcoz my code required "#RequireAdmin" to run as administrator. so the consolewrite function does not right anything. Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font] Share this post Link to post Share on other sites
water 1,771 Report post Posted April 2, 2012 Hi Syed, if ConsoleWrite doesn't help then write the debugging lines to a file. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example ScriptsExcel - Example Scripts - WikiWord - WikiPowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support Tutorials:ADO - Wiki Share this post Link to post Share on other sites
qsek 16 Report post Posted April 2, 2012 Maybe you did not read this sentence becasue i added it afterwards but i think this is your problem: did you think of what the script does when @error = 1 ? You exit the loop if FileReadLine gives an error -1 If @error = -1 Then ExitLoop Thats good, but thats not the only error code this function can give. There is also the error 1 which you can read in the helpfile is: Failure: Sets @error to 1 if file not opened in read mode or other error. That was most likely the error code when you renamed the file, which caused your script to loop forever. so add a check for @error = 1 or just do If @error Then ExitLoop This way it will exit the loop if @error is any value except 0 Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite Share this post Link to post Share on other sites