Jump to content

GUI Countdown


Recommended Posts

In my searching for a GUI with countdown, I came across the following

#include <GUIConstants.au3>
; == GUI generated with Koda ==
$Form1 = GUICreate("Count Down", 333, 128, 200, 125)
$OK = GUICtrlCreateButton("OK", 128, 80, 75, 25)
$Label = GUICtrlCreateLabel("", 128, 32, 76, 28, $SS_CENTER)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
Do
$msg=GuiGetMsg()    
    For $i = 10 to 1 Step -1
      GUICtrlSetData($Label, $i)    
      Sleep(500)
    Next
    GUICtrlSetData($Label, "Blast off!!!")
    Sleep(2000)
    ExitLoop
Until $msg=$GUI_EVENT_CLOSE OR $msg= $OK
Exit

Since then I have been trying to get the button working to no avail. Basically, neither the OK or the X will close the window. It seems to me it seems that it is stuck in the for next and can't see anything else while it is there. I have tried putting a if $msg = $OK in the for next but that didn't work. I have tried moving things around, but it just broke the script.

Link to comment
Share on other sites

Correct. As structured, the for-loop doesn't handle any GuiGetMsg events. You probably want something like this:

#include <GUIConstants.au3>
; == GUI generated with Koda ==
$Form1 = GUICreate("Count Down", 333, 128, 200, 125)
$OK = GUICtrlCreateButton("OK", 128, 80, 75, 25)
$Label = GUICtrlCreateLabel("", 128, 32, 76, 28, $SS_CENTER)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

$count = 10
$start = TimerInit()

Do
    $msg=GuiGetMsg()
    
    If TimerDiff($start) >= 500 And $count >= 0 Then
        $start = TimerInit()
        If $count = 0 Then
            GUICtrlSetData($Label, "Blast Off!")
        Else
            GUICtrlSetData($Label, $count)
        EndIf
        $count = $count - 1
    EndIf

Until $msg=$GUI_EVENT_CLOSE OR $msg= $OK
Exit
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Correct. As structured, the for-loop doesn't handle any GuiGetMsg events. You probably want something like this:

#include <GUIConstants.au3>
; == GUI generated with Koda ==
$Form1 = GUICreate("Count Down", 333, 128, 200, 125)
$OK = GUICtrlCreateButton("OK", 128, 80, 75, 25)
$Label = GUICtrlCreateLabel("", 128, 32, 76, 28, $SS_CENTER)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

$count = 10
$start = TimerInit()

Do
    $msg=GuiGetMsg()
    
    If TimerDiff($start) >= 500 And $count >= 0 Then
        $start = TimerInit()
        If $count = 0 Then
            GUICtrlSetData($Label, "Blast Off!")
        Else
            GUICtrlSetData($Label, $count)
        EndIf
        $count = $count - 1
    EndIf

Until $msg=$GUI_EVENT_CLOSE OR $msg= $OK
Exit
Thanks, that did the trick.
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...