Adding a "Stop" button to a function

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JemyM
Posts: 44
Joined: 04 Jul 2017, 11:57

Adding a "Stop" button to a function

23 Sep 2018, 02:16

I have a (non-global) function that scans the harddrive based on some criteria. The function starts a folder loop that may take up to 15-20 minutes.

The scanner have a GUI and the function/loop is started with a button called "Scan".

I have tried to add a button called "Stop" that is supposed to break the loop, but so far I haven't found a proper way to do so. Any suggestions?

For now I made it so that the "Stop" button FileAppend a text file in a cachefolder called "STOP". Then I added a FileExist in each loop that breaks the loop and delete the file if it exist.
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Adding a "Stop" button to a function

23 Sep 2018, 02:44

You could as well check a global variable in the loop. The variable gets changed with the scan and stop button. This way the loop breaks at the next iteration.
ciao
toralf
buttshark
Posts: 62
Joined: 22 Apr 2017, 20:57

Re: Adding a "Stop" button to a function

23 Sep 2018, 02:50

Creating a file seems overkill, I would just set a flag, and check that in your loop

Code: Select all

Gui, Add, Button,, Start
Gui, Add, Button,, Stop
Gui, Show
return

ButtonStart:
Loop
{
	tooltip, looping
	if(stop)
	{
		ToolTip
		return
	}
}
return

ButtonStop:
stop := true
return
I have no idea what I'm doing.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Frogrammer, gongnl, jameswrightesq, scriptor2016 and 287 guests