rojiblanco Posted October 4, 2008 Share Posted October 4, 2008 (edited) i create a GUI ,contains two button(called button1 and button2),when i click button1 the program will call a function(called function1) which contains a while true loop Now i want when i click button2 , the program will terminate function1. So could i do it? If I can ,you can tell me how to do it? Please Thanks alot! Edited October 4, 2008 by rojiblanco Link to comment Share on other sites More sharing options...
Zedna Posted October 4, 2008 Share Posted October 4, 2008 Post code you have. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Prab Posted October 4, 2008 Share Posted October 4, 2008 AutoIt can only work on one button at a time. You will need to make a helper function to do what you want. While 1 Sleep(100) If $run Then Go() WEnd Func GoHelper() $run = True EndFunc Func Go() DO STUFF HERE THAT CHECKS $terminate End Func Func Terminate() $terminate = True EndFunc Your GUI should call GoHelper and Terminate. Hope this helps. FolderLog GuiSpeech Assist Link to comment Share on other sites More sharing options...
rojiblanco Posted October 4, 2008 Author Share Posted October 4, 2008 thanks ,this is my example code #include <GUIConstantsEx.au3> Local $Button_1, $Button_2, $msg GUICreate("My GUI Button") $Button_1 = GUICtrlCreateButton("Button_1", 10, 30, 100) $Button_2 = GUICtrlCreateButton("Button_2", 120, -1) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 _Function1() Case $msg = $Button_2 MsgBox(0, 'Testing', 'Button 2 was pressed') EndSelect WEnd Func _Function1() While 1 consoleWrite("running" &@CRLF) Sleep(5000) WEnd EndFunc Link to comment Share on other sites More sharing options...
Valuater Posted October 4, 2008 Share Posted October 4, 2008 #include <GUIConstantsEx.au3> Local $Button_1, $Button_2, $msg GUICreate("My GUI Button") $Button_1 = GUICtrlCreateButton("Button_1", 10, 30, 100) $Button_2 = GUICtrlCreateButton("Button_2", 120, -1) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 AdlibEnable("_Function1", 5000) Case $msg = $Button_2 MsgBox(0, 'Testing', 'Button 2 was pressed') EndSelect WEnd Func _Function1() ConsoleWrite("running" & @CRLF) EndFunc ;==>_Function1 8) Link to comment Share on other sites More sharing options...
rojiblanco Posted October 4, 2008 Author Share Posted October 4, 2008 #include <GUIConstantsEx.au3> Local $Button_1, $Button_2, $msg GUICreate("My GUI Button") $Button_1 = GUICtrlCreateButton("Button_1", 10, 30, 100) $Button_2 = GUICtrlCreateButton("Button_2", 120, -1) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 AdlibEnable("_Function1", 5000) Case $msg = $Button_2 MsgBox(0, 'Testing', 'Button 2 was pressed') EndSelect WEnd Func _Function1() ConsoleWrite("running" & @CRLF) EndFunc ;==>_Function1 8) oh yeah thanks alot!! Great Man!!!! Link to comment Share on other sites More sharing options...
Zedna Posted October 4, 2008 Share Posted October 4, 2008 #include <GUIConstantsEx.au3> GUICreate("My GUI Button") $Button_1 = GUICtrlCreateButton("Button_1", 10, 30, 100) $Button_2 = GUICtrlCreateButton("Button_2", 120, -1) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 _Function1() EndSelect WEnd Func _Function1() While 1 If GUIGetMsg() = $Button_2 Then Return ConsoleWrite("running" & @CRLF) Sleep(100) WEnd EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
rojiblanco Posted October 4, 2008 Author Share Posted October 4, 2008 thanks Zedna about your solution So if in while loop have so many operators and it will work in several minutes. So i want when the button2 is clicked the fucntion1 will stop immediatly or 1,2 seconds . Follows your solution ,at the time i clicked, in case while loop not at IF conditions so, it will not stop as i wish. Thanks alot Link to comment Share on other sites More sharing options...
Zedna Posted October 4, 2008 Share Posted October 4, 2008 thanks Zedna about your solution So if in while loop have so many operators and it will work in several minutes. So i want when the button2 is clicked the fucntion1 will stop immediatly or 1,2 seconds . Follows your solution ,at the time i clicked, in case while loop not at IF conditions so, it will not stop as i wish. Thanks alot expandcollapse popup#include <GUIConstantsEx.au3> Global $was_stop = 0 GUICreate("My GUI Button") $Button_1 = GUICtrlCreateButton("Button_1", 10, 30, 100) $Button_2 = GUICtrlCreateButton("Button_2", 120, -1) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 _Function1() EndSelect WEnd Func _Function1() $was_stop = 0 While 1 If IsStop() Then Return ConsoleWrite("running" & @CRLF) ; some code 1 ; ... If IsStop() Then Return ; some code 2 ; ... If IsStop() Then Return Sleep(100) WEnd EndFunc Func IsStop() If $was_stop Then Return 1 If GUIGetMsg() = $Button_2 Then $was_stop = 1 Return 1 EndIf Return 0 EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
rojiblanco Posted October 4, 2008 Author Share Posted October 4, 2008 expandcollapse popup#include <GUIConstantsEx.au3> Global $was_stop = 0 GUICreate("My GUI Button") $Button_1 = GUICtrlCreateButton("Button_1", 10, 30, 100) $Button_2 = GUICtrlCreateButton("Button_2", 120, -1) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 _Function1() EndSelect WEnd Func _Function1() $was_stop = 0 While 1 If IsStop() Then Return ConsoleWrite("running" & @CRLF) ; some code 1 ; ... If IsStop() Then Return ; some code 2 ; ... If IsStop() Then Return Sleep(100) WEnd EndFunc Func IsStop() If $was_stop Then Return 1 If GUIGetMsg() = $Button_2 Then $was_stop = 1 Return 1 EndIf Return 0 EndFuncThanks It is good solution Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now