Process any error and restart the script

Advanced programming using WinTask scripting language

Process any error and restart the script

Postby Tosh on Mon Mar 03, 2014 12:04 pm

Hi,
I've finished up an automation task that runs my Windows app and enters data and clicks the mouse to accomplish my tasks. It works great... until something "random" causes the expected prompt to literally not show up. The software can run for hours and then all of a sudden it just sort of loses where it is. At that point I have to stop the script and rerun it. I have to kill the application and starts from scratch.

Wintask does pop up a box explaining the the ui element was not found. How can I process any error to just either restart the script as though it had never run, or just go back to the beginning (perhaps a label like "starthere:")?
Tosh
 
Posts: 12
Joined: Thu May 05, 2005 9:56 am

Re: Process any error and restart the script

Postby TechSupport on Tue Mar 04, 2014 8:54 am

Hello,
I've written a small example explaining one way to do what you want. In this example, the data are in an array, adapt this part to populate arrays from your Excel file or a txt/csv file. My example just sends to notepad the n elements of the array and in case of an error, the script closes notepad, launches it again and restarts the typing at the last data which has not been typed.
Code: Select all
'For this sample, I populate an array
Dim data$(100)

Function GetNextRecord$()
'This function reads the next record which is used for the form filling - in this small example, I just use the ith element of the array
GetNextRecord$=data$(i)
EndFunction

data$(0)="Record1"
data$(1)="Record2"
data$(2)="Record3"

i=0
'Ignore execution errors, and so test the return codes of the functions
#IgnoreErrors=1
'Any error occurs after the a timeout by default 30 secs.
'I shorten it a bit using #ActionTimeout, 15 seconds for the timeout
#ActionTimeout=15

   Repeat
       'Read next record to process
       record$=GetNextRecord$()

      begin:

      If record$<>"" Then
         Shell("notepad",1)
         'Here I put a pause in order to have time to create an error. During this pause, if I close the notepad window
         'an execution error will occur. Like that you can test how it works when an error occurs
         Pause 3

         ret = UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
         'I test the return code of UseWindow. If the return code is 0, the window is there, if not, there is an error and I go to begin
         if ret <> 0 then
            Goto begin
         endif

         ret = SendKeys(record$+"<Enter>")
          if ret <> 0 then
            Goto begin
         endif
         
      
         ret = CloseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
         if ret <> 0 then
            Goto begin
         endif
      
      UseWindow("NOTEPAD.EXE|CtrlNotifySink|Notepad|8",1)
      ret = Click(Button,"Do&n't Save")
      if ret <> 0 then
         Goto begin
      endif
      EndIf
   i=i+1
   Until data$(i) = ""


Regards.
WinTask Tech Support
TechSupport
 
Posts: 805
Joined: Thu Nov 16, 2006 9:58 am


Return to Scripts programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron