Jump to content

simple countdown


Recommended Posts

I found this:

;Sample countdown timer. Counts down from 10 seconds.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form= $Form1 =

GUICreate("Count Down", 296, 64, 193, 115)

$Label1 = GUICtrlCreateLabel("Time Remaining: ", 6, 21, 86, 17)

$Label2 = GUICtrlCreateLabel("time", 101, 22, 23, 17)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

Global $nTime = 10

AdlibEnable("CountDown", 1000)

While (GUIGetMsg() <> -3)

sleep(10)

if ($nTime <> -1) Then

GUICtrlSetData($Label2, $nTime)

EndIf

if ($nTime == 0) Then

$nTime -= 1

MsgBox(0, "", "Times up!!")

AdlibDisable()

EndIf

Wend

Func CountDown()

$nTime -= 1

EndFunc

but I have problem with AdlibEnable and AdlibDisable in running...

Link to comment
Share on other sites

Now why didn't you put that in the first post? You are much much MUCH more likely to get help if you post an example, rather than a vague question. Your first post sounded as though you wanted us to write an example for you, unfortunately that's not how it works around here :x

A few versions back the Adlib functions were renamed.

AdlibEnable ==> AdlibRegister

AdlibDisable ==> AdlibUnRegister

These were script breaking, but have a number of advantages over the older versions. You should be able to do a straight swap and it should work.

Link to comment
Share on other sites

;Sample countdown timer. Counts down from 10 seconds. #include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Count Down", 296, 64, 193, 115) $Label1 = GUICtrlCreateLabel("Time Remaining: ", 6, 21, 86, 17) $Label2 = GUICtrlCreateLabel("time", 101, 22, 23, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $nTime = 10 AdlibRegister("CountDown", 1000) While (GUIGetMsg() <> -3) sleep(10) if ($nTime <> -1) Then GUICtrlSetData($Label2, $nTime) EndIf if ($nTime == 0) Then $nTime -= 1 MsgBox(0, "", "Times up!!") AdlibUnRegister() EndIf Wend Func CountDown() $nTime -= 1 EndFunc

Maybe It?

Visit HugeSoft(TM) To Get Any Coding Help or Anything

Link to comment
Share on other sites

thanks!

I always want to know if it's possible, I'm looking for a script language to do it and I'm trying different way....

now:

#include <GUIConstants.au3>

; == GUI generated with Koda ==

$Form1 = GUICreate("Count Down", 333, 128, 200, 125)

$Label = GUICtrlCreateLabel("", 128, 32, 76, 28)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

GUISetState(@SW_SHOW)

$e = 5

While $e > 0

For $i = 15 to 0 Step -1

; if ($i < 10) Then

; $i = "0"&$i

; GUICtrlSetData($Label, $e&"-"&$i)

; Else

; GUICtrlSetData($Label, $e&"-"&$i)

; EndIf

GUICtrlSetData($Label, $e & ":" & CountDown($i))

Sleep(500)

Next

if ($i == 0) Then

$e = $e-1

EndIf

WEnd

Func CountDown($val)

if ($val < 10) Then

$val = "0"&$val

return $val

EndIf

EndFunc

Exit

Is it correct to pass CountDown? (to have a second format like 00 also 0)

The for cicle is stopped!

Link to comment
Share on other sites

StringFormat is the easiest way to make sure numbers are a certain length. Here I use "%02d:%02d". '%02d' means an integer ('d' = integer) padded to '2' digits using '0'. The whole thing means 2 integers ($e and $i) seperated by a ':'. I also use AdlibRegister, as it is much more reliable than sleep in a loop. GUIConstants.au3 is deprecated, use GUIConstantsEx.au3, and please use [autoit] ... [/autoit] tags to post code, as it makes it so much easier to read :x

#include <GUIConstantsEx.au3>

Global $i = 15
Global $e = 5
Global $Label

$Form1 = GUICreate("Count Down", 333, 128, 200, 125)
$Label = GUICtrlCreateLabel("", 128, 32, 76, 28)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

GUISetState(@SW_SHOW)
AdlibRegister("_Update", 1000)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _Update()
    GUICtrlSetData($Label, StringFormat("%02d:%02d", $e, $i))
    $i -= 1
    If $i < 0 Then
        $i = 15
        $e -= 1
        If $e < 0 Then
            MsgBox(0, "Done", "You reached 0.")
            Exit
        EndIf
    EndIf
EndFunc
Link to comment
Share on other sites

now I have this:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
; == GUI generated with Koda ==
$Form1 = GUICreate("Count Down", 150, 90, 125, 125, $WS_POPUP)
$Label = GUICtrlCreateLabel("", 25, 25,120,50)
GUICtrlSetFont(-1, 24, 400, 0, "verdana")
GUISetState(@SW_SHOW)
GUISetBkColor(0x66FF00)
Do
$e = 2
While $e >= 0
$i = 59
    
    While $i > 0 
    $i -=1
     If $e == 1 and $i = 30 Then 
         GUISetBkColor(0xFFFF00)
     EndIf
     If $e == 0 and $i = 30 Then 
         GUISetBkColor(0xFF0000)
     EndIf
    GUICtrlSetData($Label, StringFormat("%02d:%02d", $e, $i))
    
    Sleep(10)
    WEnd
    $e -=1
    ;Sleep(200)
    
WEnd
For $e = -1 to -59 step -1
    For $i = 0 to 59 step 1
    Sleep(10)
    GUICtrlSetData($Label, StringFormat("%03d:%02d", $e, $i))
    Next
Next
while 1
WEnd

Until GUIGetMsg() = $GUI_EVENT_CLOSE

it seems good for my work, but I need that when it arrives to -59:59 label begin to flash, it's possible?

I didn't find nothing on tutorial

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...