stop infinite loop

04/10/2016 00:13 lioncool#1
Opt("GUIOnEventMode", 1)
Global $RunState = False


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 231, 67, 1144, 503)
$Start = GUICtrlCreateButton("Start", 16, 16, 91, 25)
GUICtrlSetOnEvent(-1, "Start")
$Stop = GUICtrlCreateButton("Stop", 112, 16, 99, 25)
GUICtrlSetOnEvent(-1, "Stop")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
Sleep (1000)
WEnd


Func Start ()
$RunState = True
If $RunState then
while 1
ToolTip('working',0,0)
Sleep (1000)
WEnd
EndIf


EndFunc


Func Stop ()

$RunState = False
ToolTip('stop',0,0)

EndFunc
04/10/2016 00:25 alpines#2
Check for a variable $bRunning instead of repeating the loop over and over again. If you run Stop() set the variable to false and the loop will automatically exit.
04/10/2016 00:39 lioncool#3
i added $RunState = False still not work
04/10/2016 02:47 elmarcia#4
U only need one loop, don't use onevent methods because if u have an inside loop will fail.
Use guigetmsg() instead
04/13/2016 00:19 HaMaDa..#5
This should help you.

Code:
#RequireAdmin
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 231, 67, 1144, 503)
$Start = GUICtrlCreateButton("Start", 16, 16, 91, 25)
$Stop = GUICtrlCreateButton("Stop", 112, 16, 99, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
	Case $GUI_EVENT_CLOSE
	Case $Start
	  Start()
   Case $Stop
      Stop()
	   EndSwitch
WEnd

Func Start()
   ToolTip("Working",0,0)
EndFunc

Func Stop()
   ToolTip("",0,0)
Endfunc
04/14/2016 00:06 mlukac89#6
Quote:
Originally Posted by HaMaDa.. View Post
This should help you.

Code:
#RequireAdmin
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 231, 67, 1144, 503)
$Start = GUICtrlCreateButton("Start", 16, 16, 91, 25)
$Stop = GUICtrlCreateButton("Stop", 112, 16, 99, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Case $Start
      Start()
   Case $Stop
      Stop()
       EndSwitch
WEnd

Func Start()
   ToolTip("Working",0,0)
EndFunc

Func Stop()
   ToolTip("",0,0)
Endfunc
Here is working code u forgot to add Exit under $GUI_EVENT_CLOSE


Code:
#RequireAdmin
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 231, 67, 1144, 503)
$Start = GUICtrlCreateButton("Start", 16, 16, 91, 25)
$Stop = GUICtrlCreateButton("Stop", 112, 16, 99, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Start
          Start()
        Case $Stop
          Stop()
    EndSwitch
WEnd


Func Start()
   ToolTip("Working",0,0)
EndFunc


Func Stop()
   ToolTip("Stoped",0,0)
Endfunc
04/15/2016 01:51 HaMaDa..#7
Quote:
Originally Posted by mlukac89 View Post
Here is working code u forgot to add Exit under $GUI_EVENT_CLOSE


Code:
#RequireAdmin
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 231, 67, 1144, 503)
$Start = GUICtrlCreateButton("Start", 16, 16, 91, 25)
$Stop = GUICtrlCreateButton("Stop", 112, 16, 99, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Start
          Start()
        Case $Stop
          Stop()
    EndSwitch
WEnd


Func Start()
   ToolTip("Working",0,0)
EndFunc


Func Stop()
   ToolTip("Stoped",0,0)
Endfunc
Yea sorry, forgot it.
04/15/2016 02:27 lioncool#8
got it guys thx
04/15/2016 17:11 Lawliet#9
#closed