Jump to content

Do until button is pressed


Recommended Posts

I am trying to do something until a button on a Gui is pressed.

#include <GuiConstants.au3>
#include <misc.au3>
#include <array.au3>


$Form1 = GUICreate("Recorder", 192, 60, 193, 115)
$Button1 = GUICtrlCreateButton("Begin Recording...", 16, 8, 155, 41, 0)
GUISetState(@SW_SHOW)
$count = 0

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nmsg = $GUI_EVENT_CLOSE
            Exit
        Case $nmsg = $Button1
            GUICtrlDelete ($Button1)            
            $Button2 = GUICtrlCreateButton("Stop Recording", 16, 8, 155, 41, 0) 
            ExitLoop
        Case Else
    EndSelect
WEnd

While 1
    $nmsg2 = GUIGetMsg ()
    Select
        Case $nmsg2 = $GUI_EVENT_CLOSE
        Case Else
    Do
        $count =+1
    Until $nmsg2 = $Button2
    GUIDelete ()
    ExitLoop(2)
    EndSelect
Wend

MsgBox (0, "", $count)

here is my attempt but when i press stop the Gui does not go away and the msgbox doesn't popup.

Link to comment
Share on other sites

  • Developers

it will get stuck in the Do-Until loop.

try:

While 1
    $nmsg2 = GUIGetMsg()
    Select
        Case $nmsg2 = $GUI_EVENT_CLOSE
        Case $nmsg2 = $Button2
            GUIDelete()
            ExitLoop 
        Case Else
            $count = +1
    EndSelect
WEnd
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

#include <GuiConstants.au3>
#include <misc.au3>
#include <array.au3>


$Form1 = GUICreate("Recorder", 192, 60, 193, 115)
$Button1 = GUICtrlCreateButton("Begin Recording...", 16, 8, 155, 41, 0)
GUISetState(@SW_SHOW)
$count = 0

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nmsg = $GUI_EVENT_CLOSE
            Exit
        Case $nmsg = $Button1
            GUICtrlDelete ($Button1)            
            $Button2 = GUICtrlCreateButton("Stop Recording", 16, 8, 155, 41, 0)    
            ExitLoop
        Case Else
    EndSelect
WEnd

While 1
    $nmsg2 = GUIGetMsg ()
    Select
        Case $nmsg2 = $GUI_EVENT_CLOSE
        Case $nmsg2 = $Button2
            GUIDelete ()
            ExitLoop
        Case Else
            $count += 1
    EndSelect
Wend

MsgBox (0, "", $count)

Link to comment
Share on other sites

It can be done in one loop:

#include <GuiConstants.au3>

$Form1 = GUICreate("Recorder", 192, 60, 193, 115)
$Button1 = GUICtrlCreateButton("Begin Recording...", 16, 8, 155, 41, 0)
GUISetState(@SW_SHOW)
$count = 0
$recoding = False

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nmsg = $GUI_EVENT_CLOSE
            Exit
        Case $nmsg = $Button1
            If Not $recoding Then
                $recoding = True
                $Button2 = GUICtrlSetData($Button1, "Stop Recording")    
            Else
                ExitLoop
            EndIf
        Case Else
            If $recoding Then $count += 1
    EndSelect
WEnd

MsgBox (0, "", $count)
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...