Jump to content

Looping doubt


Recommended Posts

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 :oops: 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 by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

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 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
Link to comment
Share on other sites

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 :bye: 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" :oops: sorry for that..

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Thanks for the suggestion. But i don't think this helps me out :oops: 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]

Link to comment
Share on other sites

Hi Syed,

if ConsoleWrite doesn't help then write the debugging lines to a file.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...