Sign in to follow this  
Followers 0
qazwsx

Do until button is pressed

5 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

Ohh alright Thx for your help guys

Share this post


Link to post
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)

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