chappy Posted September 7, 2005 Share Posted September 7, 2005 I have a script that automatically runs through realtime report screens on network stats. It is very visible as it sits on a plasma screen in a common area for all to view. The problem is -- periodically the macro gets out of sync. I can detect the error message box from the program I'm running the script against and handle that - I can reset the variables and such for the script -- but I'm coming up with a brain block on how to restart the script from a certain point. Its not at the begining of the script its about 100 lines in. This would be perfect for a simple GoTo -- but I see its no longer supported ?? Any suggestions ?? thanks Link to comment Share on other sites More sharing options...
Raindancer Posted September 7, 2005 Share Posted September 7, 2005 How about this? (Pseudo Code) ;STart of Script $ran = INIRead($INI, "Ran_already", "Ran", 0) If not $ran = 1 Then IniWrite($INI, "Ran_already", "Ran", 1) ;Code as if the Script didn't crash EndIf ;Next Lines after the first 100 If Script performs OK IniWrite($INI, "Ran_already", "Ran", 0) EndIf Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer Link to comment Share on other sites More sharing options...
chappy Posted September 7, 2005 Author Share Posted September 7, 2005 thanks for the fast reply that would work to not rerun the begining of the file -- How would I restart the script? would it be a run command and then exit the current script ?? (doesn't seem clean that way ?) here is the basic layout Start -- basic entry code , login , etc (about the first 100 lines) do --- this is where I'd like to restart code takes about 1hour to run through so until looped 20 times shutoff for the night End --- restarted with windows scheduler in the morning Link to comment Share on other sites More sharing options...
Raindancer Posted September 7, 2005 Share Posted September 7, 2005 (edited) I think this could work... If you need some assistance in coding this. Just ask Edit: I don't think that you can detect the crash without making a second script which supervises the first. Edited September 7, 2005 by Raindancer Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer Link to comment Share on other sites More sharing options...
chappy Posted September 7, 2005 Author Share Posted September 7, 2005 Thanks While we were discussing -- I've nested the entire loop in another loop (whats another few lines of code) with the outer loop checking for errorcodes. In the error trap func I reset the params and exit the inner (first) loop - we'll see how it flys -- hopefully not like a wounded duck thanks again Link to comment Share on other sites More sharing options...
Raindancer Posted September 7, 2005 Share Posted September 7, 2005 Tell me :-) And If the errorcode is working well it would be nice to share it with us here :-) Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer Link to comment Share on other sites More sharing options...
GaryFrost Posted September 7, 2005 Share Posted September 7, 2005 you could always put what you need restarted in a function, if restart flag is set then call function, make sure to reset restart flag. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
chappy Posted September 7, 2005 Author Share Posted September 7, 2005 Don't know if this will help anyone -- but the nested Do Loops seems to work in trapping the error and then resetting from a given point to start the script over.. Thanks for the help $isError = 0 $LoopCount = 0 do ; error loop do ; main loop ---- Lots of code here ---- If WinActive("Microsoft Internet Explorer") Then ; check for error dialog box $isError = 1 WinActivate("Microsoft Internet Explorer") Send ("{ENTER}") ; this closes the error message box WinActivate ( <correct Window> ) ; go back to main window sleep (500) ExitLoop ; bail to reset variables and restart EndIf $LoopCount = $LoopCount + 1 ; increment counter if error not found Until $LoopCount = 5 ; main loop if $LoopCount = 5 Then ; really shut off cause I got all the way through without errors ExitLoop EndIf if $isError = 1 then ; you got here with an error -- reset all variables and go back to the begining $isError = 0 $LoopCount = 0 endif until $LoopCount = 5 ; error loop Exit Link to comment Share on other sites More sharing options...
Raindancer Posted September 7, 2005 Share Posted September 7, 2005 Use the [ CODE ] tags to post code $isError = 0 $LoopCount = 0 Do; error loop Do; main loop - - - - Lots of code here - - - - If WinActive("Microsoft Internet Explorer") Then; check for error dialog box $isError = 1 WinActivate("Microsoft Internet Explorer") Send("{ENTER}"); this closes the error message box WinActivate(<correct Window >); go back to main window Sleep(500) ExitLoop; bail to reset variables and restart EndIf $LoopCount = $LoopCount + 1; increment counter if error not found Until $LoopCount = 5; main loop If $LoopCount = 5 Then; really shut off cause I got all the way through without errors ExitLoop EndIf If $isError = 1 Then; you got here with an error -- reset all variables and go back to the begining $isError = 0 $LoopCount = 0 EndIf Until $LoopCount = 5; error loop Exit Keeps the indentation of the Lines... Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer Link to comment Share on other sites More sharing options...
Valuater Posted September 7, 2005 Share Posted September 7, 2005 one way to handle errors is...from helpRunErrorsFatal Sets if the script should terminate with a fatal error if a Run/RunWait function fails due to bad paths/file not found/Bad login IDs:1 = fatal error (default)0 = silent error (@error set to 1)secondly you can put the program in the start-up folder and put in a line like this to run during the hours you wishWhile @Hour >= 7 And @Hour < 17 Then ; place script here Wendhope those help8) Link to comment Share on other sites More sharing options...
Valuater Posted September 7, 2005 Share Posted September 7, 2005 then after handling the error... use this to "reset" or start again at the while loopContinueLoop --------------------------------------------------------------------------------Continue a While/Do/For loop.ContinueLoop [level]Parameterslevel [optional] The level of the loop to restart. The default is 1 (meaning the current loop). RemarksContinueLoop will continue execution of the loop at the expression testing statement (that is the While, Until or Next statement).8) 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