Sign in to follow this  
Followers 0
houseonfire

Stopping a loop with a button

6 posts in this topic

#1 ·  Posted (edited)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
Case $otherfunction
..
Case $start
While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Start
                While ($msg <> $Stop)
                    $msg = GUIGetMsg()
                    ConsoleWrite("Going" & @LF)
                    Sleep(10)
                Wend
                ConsoleWrite("STOPPED" & @LF)
            EndSelect
        WEnd
    EndSwitch
WEnd

When I use this method of stopping a loop using a button, the loop stops but the other buttons on the GUI stop functioning.

Can someone help me out?

Edited by houseonfire

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
Case $otherfunction
..
Case $start
While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Start
                While ($msg <> $Stop)
                    $msg = GUIGetMsg()
                    ConsoleWrite("Going" & @LF)
                    Sleep(10)
                Wend
                ConsoleWrite("STOPPED" & @LF)
            EndSelect
        WEnd
    EndSwitch
WEnd

When I use this method of stopping a loop using a button, the loop stops but the other buttons on the GUI stop functioning.

Can someone help me out?

Instead of the sub loop thing you're using, try using
GUICtrlSetState($Start, $GUI_DISABLE)
... You'll need a
#Include <GUIConstantsEx.au3>
for that to work Edited by Ichigo

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

I'm sorry but I don't see how that is going to help me stop the loop from running.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
Case $otherfunction
..
Case $start
While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Start
                While ($msg <> $Stop)
                    $msg = GUIGetMsg()
                    ConsoleWrite("Going" & @LF)
                    Sleep(10)
                Wend
                ConsoleWrite("STOPPED" & @LF)
            EndSelect
        WEnd
    EndSwitch
WEnd

When I use this method of stopping a loop using a button, the loop stops but the other buttons on the GUI stop functioning.

Can someone help me out?

You have no way to get out of the while/wend loop you start after the Case $start line unless $msg = $GUI_EVENT_CLOSE. Add another ExitLoop after ConsoleWrite("STOPPED" & @LF). Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

You have no way to get out of the while/wend loop you start after the Case $start line unless $msg = $GUI_EVENT_CLOSE. Add another ExitLoop after ConsoleWrite("STOPPED" & @LF).

Thank you very much. That worked.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

houseonfire

Not need to use many loops:

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $otherfunction
            ;
        Case $start
            While ($Msg <> $Stop)
                $Msg = GUIGetMsg()
                ConsoleWrite("STOPPED" & @LF)
                Sleep(10)
            WEnd
    EndSwitch
WEnd

:)

Edited by rasim

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