Jump to content

Stopping a loop with a button


houseonfire
 Share

Recommended Posts

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...