Sign in to follow this  
Followers 0
MythBusted

Help exiting a loop by clicking GUI button

9 posts in this topic

#1 ·  Posted (edited)

I've created a GUI which has a start pushbutton which runs a process which varies in time according to the size of the given dataset. I want to give the user the option of bailing out before the process completes, so I added a stop pushbutton and defined a GUICtrlSetOnEvent for it. When I start the process, I periodically monitor the state of a variable which is set within the stop button's event handler function, to see if the stop button has been clicked or not. However, once I'm inside this function it seems that AutoIT cannot read the state of the stop button. It only starts reading it once the process is complete.

I'd be most grateful if anyone can point to what I'm doing wrong, or if this is a limitation within AutoIT.

Thanks!

Edited by MythBusted

Share this post


Link to post
Share on other sites



It's very hard to say what's going wrong here. Do you mind sharing your script? Otherwise, you should try to work without the event mode for your GUI.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

if you use the GUIOnEventMode you have to use it for the entire GUI, GUIGetMsg will not work with GUIOnEventMode on and a GUIOnEvent function will not work without GUIOnEventMode on.

hope that helps.

Edited by smstroble

MUHAHAHAHAHA

Share this post


Link to post
Share on other sites

Make sure your doing a call out to GuiGetMsg() within your loop to set the flag.

Might need to throw a Sleep in there to give the GUI time to send it's data.

Just some ideas...

Post a snip of the code


Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The code is quite long. For the sake of not flooding this with unnecessary stuff I've only posted the related sections:

; The button declaration for the GUI

$StopButton = GUICtrlCreateButton("Cancel Data Processing", 268, 168, 195, 49, 0)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "StopButtonclick")

; The stop button event handler

Func StopButtonclick(); Cancel post-processing
        Global $stop = 1
EndFunc

; Code snippet from the running process which I want to stop with this button

Func ProcessData()
      For $i = 0 to $dataLimit
        If GUICtrlRead($StopButton) =  Then
        $oExcel.Quit                
        ProgressOff()           
        MsgBox(48, "Warning!", "Post-processing was halted prior to completion. All required files might not have been created.")
        Return
        Else
            ; Keep going
        EndIf
.
.
.
      Next
Endfunc

As a side note, all the other GUIOnEvent functions work fine.

Thanks again!

Edited by MythBusted

Share this post


Link to post
Share on other sites

Thanks for posting the code, it was easy to see what was going wrong.

Global $stop = 0

; The button declaration for the GUI

$StopButton = GUICtrlCreateButton("Cancel Data Processing", 268, 168, 195, 49, 0)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "StopButtonclick")

; The stop button event handler

Func StopButtonclick(); Cancel post-processing
        $stop = 1
EndFunc

; Code snippet from the running process which I want to stop with this button

Func ProcessData()
      For $i = 0 to $dataLimit
        If $stop  Then
        $oExcel.Quit                
        ProgressOff()            
        MsgBox(48, "Warning!", "Post-processing was halted prior to completion. All required files might not have been created.")
        Return
        Else
            ; Keep going
        EndIf
.
.
.
      Next
Endfunc

Share this post


Link to post
Share on other sites

Thanks for your help Manadar! However, I still get the same problem. It seems once inside the "ProcessData" function, and within that loop, $stop never gets read until after the function has completed and returned, no matter how many times I click the stop button. :whistle:

Share this post


Link to post
Share on other sites

I believe I found the problem. However, I don't know how to fix it or work around it.

It seems that while the ProcessData function is executing, no other functions may simultaneously run, nor will ProcessData stop in order to give StopButtonclick a chance to run briefly, changing the value of $stop. It seems AutoIT is a single-thread application.

I placed a message box within StopButtonclick. When ProcessData is running, nothing will happen no matter how many times I press the stop button. However, once ProcessData completes, a multitude of message boxes pop up, equal to the number of times I pressed the stop button. These boxes indeed show the correct $stop = 1 value, but it's too late - ProcessData has already completed.

Any thoughts on how I can work around this will be greatly appreciated.

Thanks again!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

You're right. AutoIt is a single-thread application, although you should be abled to do almost anything in a single-thread rather then a multi-thread. What you may be running into is a so called 'blocking function'. While the blocking function is being executed the script will pause at that line to let the function continue. Examples of blocking functions are msgbox and inputbox, some DLL calls and _IELoadWait and the likes.

Edited by Manadar

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0