Sign in to follow this  
Followers 0
cording12

Help end my infinite loop

2 posts in this topic

I already posted in the GUI section but it may have been the wrong place. Melba23 has been a massive help but I need to get this finished today so I'd like to post it here.

My script basically doesn't do two thing. It won't actually input the key's I tell it to and then when it does I can't exit the loops. Can someone please shed some light on this? I read through the 'Interrupt a running function' several times and no matter what I do it just won't work!

#include <GUIConstantsEx.au3>
;
Global $fRunOne = False
;
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
;
GUICreate("Test Script", 335, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ; Run this function when the [X] is clicked
;
GUICtrlCreateLabel("Key", 8, 10)
$key1 = GUICtrlCreateInput("", 35, 8, 120)
; No need to set a function for this control as it is not actioned
;
GUICtrlCreateLabel("Time", 8, 44)
$time1 = GUICtrlCreateInput("", 35, 40, 120)
; No need to set a function for this control as it is not actioned
;
$startbutton = GUICtrlCreateButton("Start", 190, 8, 60)
GUICtrlSetOnEvent($startbutton, "StartButtonPressed") ; Run this function when the button is pressed
;
$stopbutton = GUICtrlCreateButton("Stop", 190, 40, 60)
GUICtrlSetOnEvent($stopbutton, "StopButtonPressed") ; Run this function when the button is pressed
;
GUISetState(@SW_SHOW)
;
While 1
     Sleep(1000)
     ; Check if the flag has been set by the OnEvent function
     If $fRunOne Then
         ; Now start the "real" function from within the main code
         StartButtonPressed()
     EndIf
WEnd
; This function is run when the [X] is clicked
Func CLOSEClicked()
    MsgBox(0, "Stop", "GUI closed. Now Exiting")
    Exit
EndFunc   ;==>CLOSEClicked
;
; This function is run when the start button is pressed
Func StartButtonPressed()
$fRunOne = True
while 1
    $send1 = GUICtrlRead($key1)
    $sleep1 = GUICtrlRead($time1)
WEnd
MsgBox(0, "Read", "Key: " & $send1 & @CRLF & "Sleep: " & $sleep1)
Global $fRunOne = False
EndFunc   ;==>StartButtonPressed
;
; This function is run when the stop button is pressed
Func StopButtonPressed()
    MsgBox(0, "Stop", "Script Stopped. Now Exiting")
    Exit
EndFunc   ;==>StopButtonPressed

Share this post


Link to post
Share on other sites



cording12,

As you state yourself, you already have a thread running on this question, so there is no need for another. We try to stick to just the one thread per question at a time in this forum. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0