If Imagesearch matches error image, move on to next loop

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DarkSirrush
Posts: 2
Joined: 17 Jan 2020, 20:00

If Imagesearch matches error image, move on to next loop

17 Jan 2020, 20:14

Hi Everyone,

I am trying to use AHK to make generating some yearly reports easier, but I have found a problem and I am unsure how to fix it. I am using an imagesearch loop to check if a report has finished generating and can be converted to PDF, but I realized if there is no data to generate a report with, obviously this loop hangs indefinitely. After setting up a solution (second imagesearch with a match to the "no data" message), I realized that I don't want the script to continue with it's normal loop as those inputs can break the next loop. What would be the simplest way to tell AHK to increment a variable and restart the loop?

Current code as below:

Code: Select all

	Loop %var2% 
	{
		MouseClick, L, 469, 334
		Send, {Blind}0101%var1% ;Year Start
		MouseClick, L, 467, 356
		Send, {Blind}1231%var1% ;Year End
		MouseClick, L, 465, 535 ;Preview
		Loop 
		{
			ImageSearch, , , 125, 225, 750, 275, PASS.png
			if ErrorLevel = 0
					break ; image was found break loop and continue
			ImageSearch, , , 195, 395, 300, 440, FAIL.png
			if ErrorLevel = 0
				break ; image was not found break loop and continue
		}
		... more code...
		var1++
	}
		
DarkSirrush
Posts: 2
Joined: 17 Jan 2020, 20:00

Re: If Imagesearch matches error image, move on to next loop

17 Jan 2020, 22:08

telanx wrote:
17 Jan 2020, 20:26
try Continue
Thank you for this suggestion, however for some reason I could not get this to work correctly (continue would always fire, and var1 would not increment before continue fired.

However, while looking further into I noticed the goto command, which works exactly as expected. Likely I was formatting something wrong for continue, but for now goto suits my needs.

Again, thank you for your help however.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 347 guests