Jump to content

OnEventMode -- Stop function -- What am I doing wrong?


 Share

Recommended Posts

Hey there,

I have a program that I'm working on, and I have a button that's supposed to stop a running function, when it's pressed.

However, I cannot get that to work.

I put together a sample script that is set up in the same way:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=

Opt("GUIOnEventMode", 1)

Global $Form1 = GUICreate("Form1", 290, 106, 192, 124)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Global $btnStart = GUICtrlCreateButton("Start", 24, 24, 99, 49)
    GUICtrlSetOnEvent($btnStart, "_Start")

Global $btnStop = GUICtrlCreateButton("Stop", 152, 24, 99, 49)
    GUICtrlSetOnEvent($btnStop, "_Stop")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
;~  $nMsg = GUIGetMsg()
;~  Switch $nMsg
;~      Case $GUI_EVENT_CLOSE
;~          Exit

;~  EndSwitch
WEnd


Func _Start()
    Global $bStartFlag = True
    $num = 1

    While $bStartFlag

        ConsoleWrite($num & @CRLF)
        Sleep(1000)
        $num += 1

    WEnd

    ConsoleWrite("Exited loop.." & @CRLF)

EndFunc


Func _Stop()
    Global $bStartFlag = False
EndFunc


Func _Exit()
    Exit
EndFunc

 

With the code above, while the _Start() func is running, the Stop button doesn't do anything.

I even threw a MsgBox into the _Stop() func, to see if the script was at least accessing the _Stop() func. But that showed that the _Stop() func is not being accessed at all while the _Start() func is running.

I'm sure this is a simple solution that I'm just over looking. But I can't figure out what that solution is lol.

Any help here would be greatly appreciated!

Thank you in advance! :) 

Link to comment
Share on other sites

Link to comment
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
 Share

×
×
  • Create New...