SetFocus not working & "IF" statements issue

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
rjw524
Pro Scripter
Posts: 104
Joined: Wed May 09, 2012 9:45 pm
Location: Michigan

SetFocus not working & "IF" statements issue

Post by rjw524 » Wed May 23, 2012 9:35 pm

Hi All,

I'm having a bit of trouble with IF statements...

I wrote a macro that logs in to a particular site, opens a particular project file i have on the site, and sends a message to all of the profiles in my project file.

Every now and then the site cannot send the message. When this happens the site will bring up a big red X sign as notification that the message did not go through. This red X makes the image recognition tool very useful in this instance.

So, what I want to do is get the macro to do the following:

Step 1) Click the Select Message button (using Image Recognition)
Step 2) Select the message I want to send

(If the Red X was to show up it would be after this step so...)

Step 3) Check to see if the Red X shows up
Step 4) IF THE RED X SHOWS UP, THE MACRO SHOULD:
a) Page Down
b) Click the Cancel button (using Image Recognition)
c) Page Up
d) Go Back to Step 1 to try again

Step 5) IF THE RED X DOES NOT SHOW UP THE MACRO SHOULD CONTINUE WITH THE REST OF THE MACRO AS WRITTEN.


Below is the Code that corresponds to Steps 1,2,3 & 5. The code for these steps seems to work fine. The problem comes into play when I try to put in the IF statement that would correspond to Step 4

Code: Select all


Label>Start

WaitScreenImage>%SCRIPT_DIR%\ClearButton.bmp,0
Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\All Button (Project Page)_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

'A - CLICK "SELECT MESSAGE" BUTTON

WaitScreenImage>%SCRIPT_DIR%\NoneBlue.bmp,0
Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\Send Message_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif


'B - WAIT FOR SEND MESSAGE WINDOW TO OPEN

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\SendMessage_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

Wait 2.0

'C - OPEN MESSAGE DROP DOWN MENU

WaitScreenImage>%SCRIPT_DIR%\Send Message Window.bmp,0
Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\TemplatesSendMessageWindow_1.bmp,SCREEN,0,8,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>{%XArr_0%+10},YArr_0
  LClick
Endif

Wait 5.0

WaitScreenImage>%SCRIPT_DIR%\None_Template_Dropdown.bmp,0

Wait 5.0


'D - SELECT THE CHICAGO STAFF MESSAGE TEMPLATE

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\Template_A-01_Chicago_Area-Staff_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

Wait 2.0

'***THE IF STATEMENT FOR STEP 4 SHOULD GO HERE***

'E- IF RED X IS ON THE SCREEN

IF

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\RED_X.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

'F - PRESS PAGE DOWN

Press Page Down

'G - CLICK CANCEL BUTTON TO CLOSE SELECT MESSAGE WINDOW

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\CANCELBUTTON.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

'H - WAIT UNTIL THE SEND MESSAGE WINDOW GOES AWAY

WaitWindowChanged

'I - PAGE UP

Press Page Up

'J - GO BACK TO "A"

'???I HAVE NO F$%#! CLUE HOW TO CODE THIS BECAUSE I'M ALREADY USING A LABEL/GOTO.  HOW DO I EMBED A CONDITIONAL LOOP IN A LOOP?

EndIf

'IF RED X DOES NOT APPEAR ON SCREEN THEN...

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\RED_X.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound=0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\Contact Info_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

Wait 2.0

Press Page Down

Wait 1.0

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\TrackingID_2.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

Wait 0.2

Send 2000CHI

Wait 0.1

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\Send InMails_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

Wait 5.0

Press Home

WaitScreenImage>%SCRIPT_DIR%\Successfully_Sent_Message.bmp,0

Press End

Wait>0.5

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\NextPage-SendMessage_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

WaitScreenImage>%SCRIPT_DIR%\All-SendMessage.bmp,0

[color=blue]Goto>Start[/color]


I apologize if this is so long that it's hard to follow. I tried to lay out each step clearly, but if anyone can help with this that would be fantastic.

Thanks!

R.J.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed May 23, 2012 10:27 pm

Hard to tell what is real code, and what is sample code. No time for detailed look right now, but a few comments:

1. Don't use labels identical to commands. Change your label from GOTO to something like lblGOTO (I use srName for SubRoutines, lblName for labels).
2. Consider using sub routines to jump back and forth. You can use GOSUB inside an IF conditional statement.
3. WaitWindowChange needs a window name.
4. See no EndIf for the Red X If loop you are creating, where does that loop end.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

rjw524
Pro Scripter
Posts: 104
Joined: Wed May 09, 2012 9:45 pm
Location: Michigan

Post by rjw524 » Thu May 24, 2012 3:31 am

Bob Hansen wrote:Hard to tell what is real code, and what is sample code. No time for detailed look right now, but a few comments:

1. Don't use labels identical to commands. Change your label from GOTO to something like lblGOTO (I use srName for SubRoutines, lblName for labels).
2. Consider using sub routines to jump back and forth. You can use GOSUB inside an IF conditional statement.
3. WaitWindowChange needs a window name.
4. See no EndIf for the Red X If loop you are creating, where does that loop end.
Thanks again,

1) I don't use GOTO as the name of the label. I use Label>Start, GoTo>Start

2) I tried a GoSub, but it didn't take. Is is possible I inserted it incorrectly?

3) WaitWindowChange in my macro does have a name.

4) There is an EndIf for the Red X loop. It's after step 'J in the macro.

Any ideas?

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

Post by JRL » Thu May 24, 2012 4:33 am

Using labels you can jump around any way you want. But logic can get confusing very quickly. Subroutine logic can be easier to follow and thus debug. If you decide to use subroutines do not jump out of the subroutine to a label.

I made some alterations and noted the changes. I have no real way to test so that part is up to you.

Code: Select all


Label>Start

WaitScreenImage>%SCRIPT_DIR%\ClearButton.bmp,0
Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\All Button (Project Page)_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

'A - CLICK "SELECT MESSAGE" BUTTON

WaitScreenImage>%SCRIPT_DIR%\NoneBlue.bmp,0
Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\Send Message_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif


'B - WAIT FOR SEND MESSAGE WINDOW TO OPEN

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\SendMessage_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

Wait 2.0

'C - OPEN MESSAGE DROP DOWN MENU

WaitScreenImage>%SCRIPT_DIR%\Send Message Window.bmp,0
Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\TemplatesSendMessageWindow_1.bmp,SCREEN,0,8,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>{%XArr_0%+10},YArr_0
  LClick
Endif

Wait 5.0

WaitScreenImage>%SCRIPT_DIR%\None_Template_Dropdown.bmp,0

Wait 5.0


'D - SELECT THE CHICAGO STAFF MESSAGE TEMPLATE

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\Template_A-01_Chicago_Area-Staff_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

Wait 2.0

'***THE IF STATEMENT FOR STEP 4 SHOULD GO HERE***

'E- IF RED X IS ON THE SCREEN
Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\RED_X.bmp,SCREEN,0,1,XArr,YArr,NumFound
// Red X was found
If>NumFound>0

    //These two steps are not mentioned in your list
    //MouseMove>XArr_0,YArr_0
    //LClick
    ////////////////////////////////////////////////

    'F - PRESS PAGE DOWN
    Press Page Down

    'G - CLICK CANCEL BUTTON TO CLOSE SELECT MESSAGE WINDOW
    Let>FIP_SCANPIXELS=ALL
    FindImagePos>%SCRIPT_DIR%\CANCELBUTTON.bmp,SCREEN,0,1,XArr,YArr,NumFound
    If>NumFound>0
      MouseMove>XArr_0,YArr_0
      LClick
    Endif

    'H - WAIT UNTIL THE SEND MESSAGE WINDOW GOES AWAY
    WaitWindowChanged

    'I - PAGE UP
    Press Page Up

    'J - GO BACK TO "A"
    Goto>Start
EndIf
'***THE IF STATEMENT FOR STEP 4 ENDS HERE***

'IF RED X DOES NOT APPEAR ON SCREEN THEN...

//Red X was not found

Let>FIP_SCANPIXELS=ALL
//Already did this and we know the result from above
//FindImagePos>%SCRIPT_DIR%\RED_X.bmp,SCREEN,0,1,XArr,YArr,NumFound
//If>NumFound=0
  //If image is not found what will XArr_0,YArr_0 be? 
  //MouseMove>XArr_0,YArr_0
  //LClick
//EndIf

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\Contact Info_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

Wait 2.0

Press Page Down

Wait 1.0

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\TrackingID_2.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

Wait 0.2

Send 2000CHI

Wait 0.1

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\Send InMails_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

Wait 5.0

Press Home

WaitScreenImage>%SCRIPT_DIR%\Successfully_Sent_Message.bmp,0

Press End

Wait>0.5

Let>FIP_SCANPIXELS=ALL
FindImagePos>%SCRIPT_DIR%\NextPage-SendMessage_1.bmp,SCREEN,0,1,XArr,YArr,NumFound
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

WaitScreenImage>%SCRIPT_DIR%\All-SendMessage.bmp,0

[color=blue]Goto>Start[/color]

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