Jump to content
Sign in to follow this  
houseonfire

Click button to start script, click same button to stop

Recommended Posts

houseonfire

How would I go about making this script stop by clicking the same button that activated it?

I figured i needed multithreading, so Iv been trying to use this here:

But I'm not getting too far.

Thanks

I guess I don't understand how to use the multithreading maybe, or maybe I'm just doing it wrong.

Can someone please help me out?

Thanks

Edited by houseonfire

Share this post


Link to post
Share on other sites
AdmiralAlkex

You don't need or want multi-threading.

There are lots of ways to do this, some are explained in the Interrupting a running function-tutorial in the wiki, so I suggest you start there.

Share this post


Link to post
Share on other sites
somdcomputerguy

Another way to do this is like this, although I'd suggest going thru that tutorial as well.

#include <GuiConstantsEx.au3>

Opt("MustDeclareVars", 1)

Local $GUI, $Button

$GUI = GUICreate("one button - two things")
$Button = GUICtrlCreateButton(" Start ", -1, -1)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            DoSomething()
    EndSwitch
    Sleep(10)
WEnd

Func DoSomething()
    If ControlGetText("one button - two things", "", $Button) = " Start " Then
        ControlSetText("one button - two things", "", $Button, " Stop ")
        MsgBox(0, "", "The script has started doing something")
    Else
        ControlSetText("one button - two things", "", $Button, " Start ")
        MsgBox(0, "", "The script has stopped doing something")
    EndIf
EndFunc

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×