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

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:")?
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

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


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

       'Read next record to process


      If record$<>"" Then
         '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

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

WinTask Tech Support
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