Sign in to follow this  
Followers 0
zxcvbnm

simple countdown

18 posts in this topic

I'm new user of autoit, I've to implement a simple 5 minutes countdown... it is possible?

Share this post


Link to post
Share on other sites



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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

For $i = 10 To 0 Step - 1
    MsgBox(0, "", $i)
Next
MsgBox(0, "", "Blast Off!")

There's also an example of a countdown script in the helpfile.

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

Thanks a lot!

good start point...I keep working on!

Share this post


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

Share this post


Link to post
Share on other sites

It's possible, you will need to use a flag and adlib again (or sleeps in a loop):

Flag on?

==> Change bk colour to red something like that

==> Set flag off

Flag off?

==> Change bk colour back to white.

==> Set flag on

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Can you delete the icon near the clock while running the executable?

This may help, see TrayIconHide in the Helpfile.

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Thanks!

Share this post


Link to post
Share on other sites

You bet. Good luck.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

I built the window always on top,can you make it draggable?

$Form1 = GUICreate("Count Down", 250, 70, 125, 125, $WS_POPUP, $WS_EX_TOPMOST )

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