Jump to content
Sign in to follow this  
chappy

Restarting after an Error

Recommended Posts

chappy

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

Share this post


Link to post
Share on other sites
Raindancer

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

Share this post


Link to post
Share on other sites
chappy

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

Share this post


Link to post
Share on other sites
Raindancer

I think this could work... If you need some assistance in coding this. Just ask :whistle:

Edit: I don't think that you can detect the crash without making a second script which supervises the first.

Edited by Raindancer

Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer

Share this post


Link to post
Share on other sites
chappy

Thanks :whistle:

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 :dance:

thanks again

Share this post


Link to post
Share on other sites
Raindancer

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

Share this post


Link to post
Share on other sites
GaryFrost

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.

 

Share this post


Link to post
Share on other sites
chappy

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 :whistle:

$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

Share this post


Link to post
Share on other sites
Raindancer

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

Share this post


Link to post
Share on other sites
Valuater

one way to handle errors is...

from help

RunErrorsFatal 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 wish

While @Hour >= 7 And @Hour < 17 Then
; place script here
Wend

hope those help

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Valuater

then after handling the error... use this to "reset" or start again at the while loop

ContinueLoop

--------------------------------------------------------------------------------

Continue a While/Do/For loop.

ContinueLoop [level]Parameters

level [optional] The level of the loop to restart. The default is 1 (meaning the current loop).

Remarks

ContinueLoop will continue execution of the loop at the expression testing statement (that is the While, Until or Next statement).

8)

NEWHeader1.png

Share this post


Link to post
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
Sign in to follow this  

×