iAmNewbe Posted February 3, 2019 Share Posted February 3, 2019 (edited) AutoIT Versions: 3.3.14.5 & 3.3.14.2 Once the Counter Button is pressed all events stop working. I understand the issue is the loop inside displayLoop Function prevents the inital event from stopping and new events from occuring. Not sure how to make this application work without the loop inside displayLoop function. Originally I used images to display the counter numbers but since you do not have access to that I changed the code to display text numbers. Trying to create a Timer Counter eventually for time management. How do I make the counter count without the loop or does it need to be somewhere else? In another thread Jos said to look at this for help --> https://www.autoitscript.com/wiki/Managing_Multiple_GUIs Though in my use case I do not understand. My Code Below --------------------------- expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> #include <FontConstants.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode HotKeySet("{ESC}", "endApp") Global $title = "A Little Counter Application" Global $stopLoop = "No" Global $imageNumbers[11] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":"] Global $theApplication = GUICreate($title, 300, 200, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "endApp") Global $btnStartDisplayLoop = GUICtrlCreateButton("Start Count", 90, 120, 100, 30) GUICtrlSetOnEvent($btnStartDisplayLoop, "btnPress") GUISetFont(24, $FW_NORMAL, $GUI_FONTNORMAL, "Arial") Global $imgMIN1 = GUICtrlCreateLabel($imageNumbers[0], 50, 50) Global $imgMIN2 = GUICtrlCreateLabel($imageNumbers[0], 100, 50) Global $spacer = GUICtrlCreateLabel($imageNumbers[10], 150, 50) Global $imgSEC1 = GUICtrlCreateLabel($imageNumbers[0], 200, 50) Global $imgSEC2 = GUICtrlCreateLabel($imageNumbers[0], 250, 50) GUISetState(@SW_SHOW, $theApplication) Func displayLoop($duration = 5) Dim $stopLoop, $min, $sec While 1 if $stopLoop == "Yes" Then ExitLoop If $min == $duration Then ExitLoop EndIf $sec = $sec + 1 If($sec == 60) Then $min = $min + 1 $sec = 0 EndIf $mins = returnArray($min) GUICtrlSetData($imgMIN1, $imageNumbers[$mins[1]]) GUICtrlSetData($imgMIN2, $imageNumbers[$mins[2]]) $secs = returnArray($sec) GUICtrlSetData($imgSEC1, $imageNumbers[$secs[1]]) GUICtrlSetData($imgSEC2, $imageNumbers[$secs[2]]) Sleep(1000) WEnd MsgBox(0,"","Counter Stopped") EndFunc Func returnArray($number) Local $newArray[3] if $number = "" Then $number = 0 Local $numberArray = StringSplit($number, "") If($numberArray[0] == 1) Then $newArray[0] = 2 $newArray[1] = 0 $newArray[2] = $numberArray[1] $numberArray = $newArray EndIf return $numberArray EndFunc Func btnPress() Dim $stopLoop $getBtnText = GUICtrlRead($btnStartDisplayLoop, $GUI_READ_EXTENDED) If $getBtnText == "Start Count" Then GUICtrlSetData($btnStartDisplayLoop, "Stop Count") $stopLoop = "No" displayLoop() ; Starts Display Loop ElseIf $getBtnText == "Stop Count" Then GUICtrlSetData($btnStartDisplayLoop, "Start Count") $stopLoop = "Yes" EndIf EndFunc Func endApp() Local $exitCode = MsgBox(68,'',"Are you sure you want to quit?") If($exitCode == 6) Then GUIDelete($theApplication) Exit EndIf EndFunc While 1 ;~ Keep Application Running WEnd Once button is initially pressed it does not respond and the close modal button does not work. The hotkey {ESC} does work. I am lost at how to make this work, please help. Edited February 3, 2019 by iAmNewbe Link to comment Share on other sites More sharing options...
Jury Posted February 3, 2019 Share Posted February 3, 2019 Without looking into this much have you tried the ContinueLoop function? Link to comment Share on other sites More sharing options...
iAmNewbe Posted February 3, 2019 Author Share Posted February 3, 2019 The issue is that once the Loop inside displayLoop starts all events, buttons stop working. ContinueLoop would only come into play when their is a condition that when met the rest of the code is needed to be bypassed for that iteration of the loop. In my use case and way the application is currently written, this is not something that fits with the existing code. Link to comment Share on other sites More sharing options...
iAmNewbe Posted February 3, 2019 Author Share Posted February 3, 2019 I am trying to understand how to make a loop that iterates counters and displays the count live in application while keeping functionality of buttons, modals, events etc... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2019 Moderators Share Posted February 3, 2019 (edited) iAmNewbe, The Wiki tutorial you need to read is Interrupting a running function - that explains how to do what you wish. I am a bit busy at the moment but if I find time I will try and modify your code this afternoon. M23 Edit: Easier than I thought: expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> #include <FontConstants.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode HotKeySet("{ESC}", "endApp") Global $title = "A Little Counter Application" Global $stopLoop = "Yes" Global $imageNumbers[11] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":"] Global $theApplication = GUICreate($title, 300, 200, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "endApp") Global $btnStartDisplayLoop = GUICtrlCreateButton("Start Count", 90, 120, 100, 30) GUICtrlSetOnEvent($btnStartDisplayLoop, "btnPress") GUISetFont(24, $FW_NORMAL, $GUI_FONTNORMAL, "Arial") Global $imgMIN1 = GUICtrlCreateLabel($imageNumbers[0], 50, 50) Global $imgMIN2 = GUICtrlCreateLabel($imageNumbers[0], 100, 50) Global $spacer = GUICtrlCreateLabel($imageNumbers[10], 150, 50) Global $imgSEC1 = GUICtrlCreateLabel($imageNumbers[0], 200, 50) Global $imgSEC2 = GUICtrlCreateLabel($imageNumbers[0], 250, 50) GUISetState(@SW_SHOW, $theApplication) Func displayLoop($duration = 5) Dim $stopLoop, $min, $sec While 1 if $stopLoop == "Yes" Then ExitLoop If $min == $duration Then ExitLoop EndIf $sec = $sec + 1 If($sec == 60) Then $min = $min + 1 $sec = 0 EndIf $mins = returnArray($min) GUICtrlSetData($imgMIN1, $imageNumbers[$mins[1]]) GUICtrlSetData($imgMIN2, $imageNumbers[$mins[2]]) $secs = returnArray($sec) GUICtrlSetData($imgSEC1, $imageNumbers[$secs[1]]) GUICtrlSetData($imgSEC2, $imageNumbers[$secs[2]]) Sleep(1000) WEnd MsgBox(0,"","Counter Stopped") EndFunc Func returnArray($number) Local $newArray[3] if $number = "" Then $number = 0 Local $numberArray = StringSplit($number, "") If($numberArray[0] == 1) Then $newArray[0] = 2 $newArray[1] = 0 $newArray[2] = $numberArray[1] $numberArray = $newArray EndIf return $numberArray EndFunc Func btnPress() Dim $stopLoop $getBtnText = GUICtrlRead($btnStartDisplayLoop, $GUI_READ_EXTENDED) If $getBtnText == "Start Count" Then GUICtrlSetData($btnStartDisplayLoop, "Stop Count") $stopLoop = "No" $vRun = True ;displayLoop() ; Starts Display Loop ElseIf $getBtnText == "Stop Count" Then GUICtrlSetData($btnStartDisplayLoop, "Start Count") $stopLoop = "Yes" EndIf EndFunc Func endApp() Local $exitCode = MsgBox(68,'',"Are you sure you want to quit?") If($exitCode == 6) Then GUIDelete($theApplication) Exit EndIf EndFunc While 1 ;~ Keep Application Running Sleep(10) ; Stop CPU from frying!!!!!!! If $stopLoop = "No" Then displayLoop() ; Starts Display Loop EndIf WEnd The tutorial explains why it works - but do ask if anything is still unclear. Edited February 3, 2019 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
iAmNewbe Posted February 3, 2019 Author Share Posted February 3, 2019 So the solution is to not start the second loop via the event of the button press and instead set flags? I think I ran into this before in a different scenerio.. Weird. I do have a question about the use of Quote If $stopLoop = "No" Then Shouldn't this be a comparison operator instead of an assignment? I see that it works the same both ways, when changing the code but I don't understand this. Have seen it with loop examples in the documentation also, I thought that this would create never ending loops forever assigning to the variable being checked? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2019 Moderators Share Posted February 3, 2019 iAmNewbie, Quote So the solution is to not start the second loop via the event of the button press and instead set flags? Did you read the tutorial to which I linked? If you start a function from the main loop it is interruptable by OnEvent calls - if you start it from an OnEvent call it is not. Quote Shouldn't this be a comparison operator instead of an assignment? If you read the Operators page in the Help file you will see that AutoIt is clever enough to use "=" as both - and that the "==" operator is a special case-sensitive comparison operator. M23 iAmNewbe 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
iAmNewbe Posted February 3, 2019 Author Share Posted February 3, 2019 (edited) Yes, I understand. I changed my code to reflect this and it works, thank you. I had forgotten about that operator thing with AutoIt. I do not use it an a daily basis and every other language I use does not have that. Thanks for reminding me. I appreciate your help, you helped solve my problem. Edited February 3, 2019 by iAmNewbe Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2019 Moderators Share Posted February 3, 2019 iAmNewbie, Glad I could help. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
iAmNewbe Posted February 11, 2019 Author Share Posted February 11, 2019 Ran into an issue where if you drag the window or mouse click and hold the title bar the script pauses which throws the counter off. Is there a way to keep the script running while the window is being moved around? Link to comment Share on other sites More sharing options...
careca Posted February 11, 2019 Share Posted February 11, 2019 Doesn't it update once you release? Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
iAmNewbe Posted February 11, 2019 Author Share Posted February 11, 2019 The problem is that it stops while the mouse button, primary, is held down. I do not want it to stop at all. If you add a time begin, when the count was started and a time stop when the count terminated the time does not match the counter. This is an example of a use case where you do not want the script to pause. Yes, once the button is released the count continues. It should not stop at all though. 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