Prompt Script End if Error Message is encountered.

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Prompt Script End if Error Message is encountered.

Post by winstein » Thu Dec 06, 2012 2:47 pm

Is there any way to stop the script when an error message pops up? What I am thinking is that, in case there is an error message while the script is being performed, then the script will immediately end.

One thing I thought of is to use Image Recognition to scan the error message if it pops up, but is it possible for it to make this work for the duration of the script?

Thanks for reading.
PPQ

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Dec 06, 2012 3:29 pm

Look at help for OnEvent> You could use image recognition in a custom event. (might be a lot of overhead and slow things down) Or you might be able to perform an action (such as Exit>) based on the error window name.

winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Post by winstein » Fri Dec 07, 2012 10:46 am

JRL wrote:Look at help for OnEvent> You could use image recognition in a custom event. (might be a lot of overhead and slow things down) Or you might be able to perform an action (such as Exit>) based on the error window name.
I see. However, since the error message of the program I am using is quite similar to the name of the non-error portions of the program, it would be difficult to use the window name, which is why I am looking into image recognition here.

Is there any way to disable the event (because I won't want to repeat the handling as long as the image is on-screen.

Thanks for reading.
PPQ

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Dec 07, 2012 4:18 pm

Here's a couple of samples. The first uses image recognition and the second uses text comparison. Both methods have good points and bad points. If they both work, use the one that suits you. If neither work let us know and we'll try something else.

The Window_NewActive event handler activates every time a new window pops up. It doesn't repeat, it only activates at that moment when a new active window displays. Its my favorite method of dealing with sporadic windows. I have a script that happens to be running on another computer at this moment, where the Window_NewActive event handler deals with more than 20 different windows that might pop up during the process the script is controlling.

Image recognition on a newly activated window

Code: Select all

OnEvent>WINDOW_NEWACTIVE,0,0,CheckOutThisWindow

Let>NeedleFileName=C:\MyPath\MyBMPfile.BMP

SRT>CheckOutThisWindow
  FindImagePos>NeedleFileName,SCREEN,0,1,X_pos,Y_pos,NumFound
  If>NumFound>0
    //Do what needs to be done for this particular window.
  EndIf
END>CheckOutThisWindow
Text comparison on a newly activated window

Code: Select all

OnEvent>WINDOW_NEWACTIVE,0,0,CheckOutThisWindow

//Text is case sensitive
Let>TextToCompare=Something is BROKEN!

SRT>CheckOutThisWindow
  Let>WIN_USEHANDLE=1
    GetActiveWindow>CurWinHandle,CurWinX,CurWinY,CurWinW,CurWinH
    GetWindowTextEx>CurWinHandle,WindowTextResult
  Let>WIN_USEHANDLE=0
  Separate>WindowTextResult,TextToCompare,CompareTextResult
  If>CompareTextResult_Count>1
    //Do what needs to be done for this particular window.
  EndIf
END>CheckOutThisWindow

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts