Jump to content
Macro Express Forums

How to limit repeat until ?


PotterHarry

Recommended Posts

Hi, I have read some of the forum questions with similar issues, but I admit I cannot understand the solution. PLEASE help! I am placing the mouse pointer at the end of a series of web page panels. The word YES and NO appear in Red or Black, and I want to use Get Pixel Under Mouse to detect either answer. So, the pointer starts at 496,724 and then travels left. I can detect red, but I cannot limit how far the mouse goes along looking for red. How do I exit the loop when red is not detected? I tried to get it limited with D1 variable, but this does not work?

 

Mouse Move Screen 496, 724

Variable Set Integer %N12% to 0

Variable Set Decimal %D1% to 0

Repeat Until %D1% = 100

Get Pixel: Under Mouse into %N1%

If Variable %T1% = "7143674"

Variable Modify Integer: %N12% = %N12% + 1

Variable Modify Decimal: %D1% = %D1% + 1

End If

Get Mouse Position Screen: %N2%, %N4%

Variable Modify Integer: %N2% = %N2% - 1

Mouse Move Screen %N2%, %N4%

Repeat End

 

If Variable %N12% > 0

Variable Modify Integer: %N51% = %N51% + 1

End If

Repeat Exit

Launch and Activate: "notepad.exe"

Text Type: %N12% %N51%

Delay 1 Seconds

Window Close: Current Window

Link to comment
Share on other sites

First, after getting the pixel color into N1, you are checking T1 for the desired color value. Easy mistake to make -- but change it to say

If Variable %N1% = 7143674

 

Also, the incrementing of D1

Variable Modify Decimal: %D1% = %D1% + 1

is controlled by the IF statement, so the value is bumped up ONLY if you have detected a pixel of color 7143674. If you want to exit the REPEAT loop after checking 100 pixels, then move the D1 increment down one line, so it falls after the END IF.

 

Last, the macro will work perfectly well with your technique of moving the mouse and checking the color under the mouse each time through the REPEAT loop. However, it will work faster if you simply get pixel color at specific coordinates, without moving the mouse there at all. It's more fun to watch the mouse move, and it's also good for debugging because you can see, visually, where you are checking. But it does slow things down. I usually code the mouse movement during testing, then disable that line of code after the macro is working.

 

P.S. The REPEAT EXIT is out of place and serves no function. It only has effect if it falls between the REPEAT and REPEAT END statements. I would have expected to see it right after the incrementing of N12, so you would jump to the REPEAT END as soon as a single pixel is found with color 7143674. But it looks like you are using N12 to indicate the desired color has been found (or not) within 100 cycles, so the REPEAT EXIT can be skipped, or moved to after the N12 increment.

Link to comment
Share on other sites

 

Last, the macro will work perfectly well with your technique of moving the mouse and checking the color under the mouse each time through the REPEAT loop. However, it will work faster if you simply get pixel color at specific coordinates, without moving the mouse there at all.

 

True, but be aware that on some Web pages, a mouse pointer hovering over an element causes its colour to change.

Link to comment
Share on other sites

Thanks again, that was right on the mark. It works very elegantly. There is no colour change on hover, no the reason I couldn't test one set pixel, was the web site operator for some reason changes the width of the tables. Even as I prepared the original macro, I found that next day the macro was sampling the next column, so this was my idea to scan across several narrow columns and hopefully could not miss the pixel colour event. I have copied my corrected code here for anyone facing the same dilemma. rberq your answer was very easy to follow, most grateful.

 

Mouse Move Screen 503, 699

Variable Set Integer %N12% to 0

Variable Set Decimal %D1% to 0

Repeat Until %D1% = 100

Get Pixel: Under Mouse into %N1%

If Variable %N1% = 7143674

Variable Modify Integer: %N12% = %N12% + 1

End If

Variable Modify Decimal: %D1% = %D1% + 1

Get Mouse Position Screen: %N2%, %N4%

Variable Modify Integer: %N2% = %N2% - 1

Mouse Move Screen %N2%, %N4%

Repeat End

HERE I AM INCREMENTING ANOTHER VARIABLE IN CASE RED OCCURS MORE THAN

ONCE IN THE PASS:

If Variable %N12% > 0

Variable Modify Integer: %N51% = %N51% + 1

End If

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...