youtuber Posted January 13, 2018 Share Posted January 13, 2018 (edited) Hi friends, how do I use the start and stop button when pulling sequences from the for loop? #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> Local $aArray[10] = ["Num1", "Num2", "Num3", "Num4", "Num5", "Num6", "Num7", "Num8", "Num9", "Num10"] $Form1 = GUICreate("Form1", 489, 353, 192, 130) $ButtonStartStop = GUICtrlCreateButton("Start", 176, 248, 75, 25) $Edit1 = GUICtrlCreateEdit("", 104, 48, 233, 129) GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonStartStop For $i = 0 To UBound($aArray)-1 If GUICtrlRead($ButtonStartStop) = "Stop" Then GUICtrlSetData($ButtonStartStop, "Start") Sleep(100) ExitLoop Else GUICtrlSetData($ButtonStartStop, "Stop") GUICtrlSetData($Edit1, $aArray[$i] & @CRLF,1) EndIf Next EndSwitch WEnd Edited January 13, 2018 by youtuber Link to comment Share on other sites More sharing options...
iamtheky Posted January 14, 2018 Share Posted January 14, 2018 (edited) whats the endgame? Most things that "loop through a set of selections until you press stop" are not actually looping through the things. They are just waiting for you to press stop and pseudo-randomly selecting one, especially if there is no need to present the user a visual to even pretend that's what is going on. Edited January 14, 2018 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
youtuber Posted January 14, 2018 Author Share Posted January 14, 2018 I do not understand what you said. is there a way to stop the for loop with the button when pulling directories? Link to comment Share on other sites More sharing options...
iamtheky Posted January 14, 2018 Share Posted January 14, 2018 (edited) of course, but a big ass Press Your Luck board seems overkill. i question the need for a loop at all. Why not just present a directory when they press stop, having done the math you want for it's selection? number of items per second in the loop * how many seconds they took to press it, modulo ubound-1. Edited January 14, 2018 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
youtuber Posted January 14, 2018 Author Share Posted January 14, 2018 This is just an example. It does not matter how many seconds it will stop. I just want to stop the cycle with the button and resume where I left off Link to comment Share on other sites More sharing options...
Xandy Posted January 14, 2018 Share Posted January 14, 2018 (edited) Pull messages in the loop: $msg = GUIGetMsg() It's not beautiful, but it's what you're asking for I think. $counterStart = 0 For $i = $counterStart To UBound($aArray)-1 If GUIGetMsg() = $idButton Then $counterStart = $i ExitLoop EndIf Next Never-mind, I'm not prepared to solve this atm. I shouldn't have said anything. My bad Edited January 14, 2018 by Xandy youtuber 1 Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
iamtheky Posted January 14, 2018 Share Posted January 14, 2018 (edited) This is what you are describing, i believe. But i still question the need to actually iterate through the loop whilst waiting for the stop button to be pressed.... expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $fInterrupt = 0 $hGUI = GUICreate("Test", 100, 100) $hButton_1 = GUICtrlCreateButton("START", 10, 10, 80, 30) $hButton_2 = GUICtrlCreateButton("STOP", 10, 50, 80, 30) $Counter = 1 GUISetState() GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_1 $Counter = _Func_1() + 1 Case $hButton_2 _Func_2() EndSwitch WEnd Func _Func_1() $fInterrupt = 0 For $i = $Counter To 30 ConsoleWrite("SelectItem: " & $i & @CRLF) If $fInterrupt <> 0 Then ConsoleWrite("!STOPPED AT ITEM " & $i & @CRLF) Return $i EndIf Sleep(100) If $i = 30 Then $i = 0 Next EndFunc Func _Func_2() return EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $hButton_2 Then $fInterrupt = 1 Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND modified from Melbas here: And if I know how many seconds elapsed between when you started and when you pressed the button, then I know where you stopped and where I need to resume. The actual visualization is nice but not ancillary. Edited January 14, 2018 by iamtheky youtuber and Xandy 2 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
kylomas Posted January 14, 2018 Share Posted January 14, 2018 youtuber, Another of many ways to do this... expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <file.au3> Local $aFiles = _FileListToArrayRec('c:\k\autoit', '*', 1, 1, 1, 2) If @error Then Exit MsgBox(17, 'Error', @extended) $Form1 = GUICreate("My File List") $ButtonStartStop = GUICtrlCreateButton("Start", 10, 375, 380, 20) $Edit1 = GUICtrlCreateEdit("", 10, 10, 380, 360) GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonStartStop If GUICtrlRead($ButtonStartStop) = "Stop" Then GUICtrlSetData($ButtonStartStop, "Start") AdlibUnRegister('Files') ContinueLoop EndIf If GUICtrlRead($ButtonStartStop) = 'Start' Then GUICtrlSetData($ButtonStartStop, "Stop") AdlibRegister('Files', 100) EndIf EndSwitch WEnd Func Files() Local Static $idx = 0 GUICtrlSetData($Edit1, $aFiles[$idx] & @CRLF, 1) $idx += 1 EndFunc ;==>Files kylomas Xandy and youtuber 2 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted January 14, 2018 Share Posted January 14, 2018 (edited) ...and the last one, based on the 3rd example from here, the OnEventMode way expandcollapse popup#include <GUIConstantsEx.au3> Opt("GuiOnEventMode", 1) Global $stop = 1 Local $aArray[10] = ["Num1", "Num2", "Num3", "Num4", "Num5", "Num6", "Num7", "Num8", "Num9", "Num10"] $Form1 = GUICreate("Form1", 489, 353, 192, 130) GUISetOnEvent($GUI_EVENT_CLOSE, "_exit") $ButtonStartStop = GUICtrlCreateButton("Start", 176, 248, 75, 25) GUICtrlSetOnEvent(-1, "_stop") $Edit1 = GUICtrlCreateEdit("", 104, 48, 233, 129) GUISetState(@SW_SHOW) While 1 Sleep(10) If not $stop Then _loop() WEnd Func _stop() $stop = not $stop EndFunc Func _loop() Local Static $index For $i = $index To UBound($aArray)-1 If $stop Then GUICtrlSetData($ButtonStartStop, "Start") Exitloop Else $index += 1 GUICtrlSetData($ButtonStartStop, "Stop") GUICtrlSetData($Edit1, $aArray[$i] & @CRLF,1) If $index = UBound($aArray) Then GUICtrlSetData($ButtonStartStop, "End !") Sleep(500) EndIf Next EndFunc Func _exit() Exit Msgbox(0,"", "bye") EndFunc Edit "I do not understand what you said."Yes. @iamtheky sometimes has an alien way of thinking that we humans cant understand ... Edited January 14, 2018 by mikell youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted January 14, 2018 Author Share Posted January 14, 2018 @mikell I can not use a second case expandcollapse popup#include <GUIConstantsEx.au3> Opt("GuiOnEventMode", 1) Global $stop = 1 Local $aArray[10] = ["Num1", "Num2", "Num3", "Num4", "Num5", "Num6", "Num7", "Num8", "Num9", "Num10"] $Form1 = GUICreate("Form1", 489, 353, 192, 130) GUISetOnEvent($GUI_EVENT_CLOSE, "_exit") $ButtonStartStop = GUICtrlCreateButton("Start", 176, 248, 75, 25) GUICtrlSetOnEvent(-1, "_stop") $Button2 = GUICtrlCreateButton("Button2", 320, 248, 75, 25) $Edit1 = GUICtrlCreateEdit("", 104, 48, 233, 129) GUISetState(@SW_SHOW) While 1 Sleep(10) If not $stop Then _loop() $nMsg = GUIGetMsg() Switch $nMsg Case $Button2 MsgBox(0,"","Button case") EndSwitch WEnd Func _stop() $stop = not $stop EndFunc Func _loop() Local Static $index For $i = $index To UBound($aArray)-1 If $stop Then GUICtrlSetData($ButtonStartStop, "Start") Exitloop Else $index += 1 GUICtrlSetData($ButtonStartStop, "Stop") GUICtrlSetData($Edit1, $aArray[$i] & @CRLF,1) If $index = UBound($aArray) Then GUICtrlSetData($ButtonStartStop, "End !") Sleep(500) EndIf Next EndFunc Func _exit() Exit Msgbox(0,"", "bye") EndFunc Link to comment Share on other sites More sharing options...
mikell Posted January 14, 2018 Share Posted January 14, 2018 Yes, you have to choose between the 2 modes, either OnEvent mode or GuiGetMsg mode. You can't use both together So in your code if you choose OnEvent mode, then you have to create a function to be launched using $Button2 and GUICtrlSetOnEvent($Button2, "_func_for_button2") youtuber 1 Link to comment Share on other sites More sharing options...
iamtheky Posted January 14, 2018 Share Posted January 14, 2018 5 hours ago, mikell said: "I do not understand what you said."Yes. @iamtheky sometimes has an alien way of thinking I do my best to speak how i code, by nesting all my thoughts together in one line and hitting F5. youtuber and Xandy 2 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted January 14, 2018 Share Posted January 14, 2018 1 hour ago, iamtheky said: nesting all my thoughts together in one line and hitting F5 Reason why the result is sometimes amazing and I mostly like it - my masochistic side Link to comment Share on other sites More sharing options...
youtuber Posted January 14, 2018 Author Share Posted January 14, 2018 @mikell How can I run a regex code here? expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> Opt("GuiOnEventMode", 1) Global $stop = 1 Local $aArray[10] = ["Num1", "Num2", "Num3", "Num4", "Num5", "Num6", "Num7", "Num8", "Num9", "Num10"] $Form1 = GUICreate("Form1", 489, 353, 192, 130) GUISetOnEvent($GUI_EVENT_CLOSE, "_exit") $ButtonStartStop = GUICtrlCreateButton("Start", 176, 248, 75, 25) GUICtrlSetOnEvent(-1, "_stop") $Edit1 = GUICtrlCreateEdit("", 104, 48, 233, 129) GUISetState(@SW_SHOW) While 1 Sleep(10) If not $stop Then _loop() WEnd Func _stop() $stop = not $stop EndFunc Func _loop() Local Static $index For $i = $index To UBound($aArray)-1 If $stop Then GUICtrlSetData($ButtonStartStop, "Start") Exitloop Else $index += 1 $arrayregex = StringRegExp($aArray[$i], 'Num(.?)', 3) ;~ _ArrayDisplay($arrayregex) GUICtrlSetData($ButtonStartStop, "Stop") GUICtrlSetData($Edit1, $arrayregex & @CRLF,1) If $index = UBound($aArray) Then GUICtrlSetData($ButtonStartStop, "End !") Sleep(500) EndIf Next EndFunc Func _exit() Exit EndFunc Link to comment Share on other sites More sharing options...
mikell Posted January 14, 2018 Share Posted January 14, 2018 It depends on what the regex is intended to do. Using flag 3 it returns an array, but an Edit displays strings, not arrays In the particular case of your current code the array has one element only so something like this may work $arrayregex = StringRegExp($aArray[$i], 'Num(.?)', 3) ;~ _ArrayDisplay($arrayregex) ; GUICtrlSetData($ButtonStartStop, "Stop") If IsArray($arrayregex) Then GUICtrlSetData($Edit1, $arrayregex[0] & @CRLF,1) but in the real life you will probably need _ArrayToString or something else youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted January 14, 2018 Author Share Posted January 14, 2018 Thank you @mikell I learned some things very well 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