Sign in to follow this  
Followers 0

How to create a countdown timer in autoit?

39 posts in this topic

Posted (edited)

Hellow id just like to ask how to create a countdown timer in autoit

I started with this code: It was the GUI of this program

The timer has HH:MM:SS Hours/Minute/Seconds

Countdown Timer

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=D:\Program Files\koda_1.7.3.0\Forms\timer.kxf
$Form1 = GUICreate("Timer", 222, 119, 346, 191)
$Label1 = GUICtrlCreateLabel("00", 0, 8, 40, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel(":", 48, 8, 13, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("00", 72, 8, 40, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel(":", 120, 8, 13, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("00", 136, 8, 40, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Start Countdown", 0, 64, 89, 33)
$Button2 = GUICtrlCreateButton("Stop Countdown", 104, 64, 97, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
                Case $button1
                ;countdown timer start
                Case $button2
                ;countdown timer stop

    EndSwitch
WEnd

I dont use the Sleep() Function

...

I need codes :unsure:

Edited by GianAutoitprogrammer

Share this post


Link to post
Share on other sites



Posted

An example :

#include <WindowsConstants.au3>

Global $SS_CENTER, $_CompteArebour = 60000, $_Minutes, $_Seconds

$_GuiCountDown = GUICreate ( "CountDown...", 500, 200, @DesktopWidth/2 -250, @DesktopHeight/2 -100, $WS_EX_TOPMOST  )
GUISetBkColor ( 0xFFFF00 )
$TimeLabel = GUICtrlCreateLabel ( "", 35, -10, 480, 180, $SS_CENTER )
GUICtrlSetFont ( -1, 125, 800 )
GUISetState ( )
WinSetOnTop ( $_GuiCountDown, "", 1 )
$TimeTicks = TimerInit ( )

While 1
    _Check ( )
    Sleep ( 200 )
WEnd

Func _Check ( )
    $_CompteArebour -= TimerDiff ( $TimeTicks )
    $TimeTicks = TimerInit ( )
    Local $_MinCalc = Int ( $_CompteArebour / ( 60 * 1000 ) ), $_SecCalc = $_CompteArebour - ( $_MinCalc * 60 * 1000 )
    $_SecCalc = Int ( $_SecCalc / 1000 )
    If $_MinCalc <= 0 And $_SecCalc <= 0 Then
        GUISetBkColor ( 0xFF0000, $_GuiCountDown )
        GUICtrlSetData ( $TimeLabel, "Bye !" )
        Sleep ( 1000 )
        ; If @Compiled Then Shutdown ( 13 )
        Exit
    Else
        If $_MinCalc <> $_Minutes Or $_SecCalc <> $_Seconds Then
            $_Minutes = $_MinCalc
            $_Seconds = $_SecCalc
            GUICtrlSetData ( $TimeLabel, StringFormat ( "%02u" & ":" & "%02u", $_Minutes, $_Seconds ) )
            If $_Minutes = 0 And $_Seconds <= 10 Then
                Beep ( 1200, 100 )
                GUISetBkColor ( 0xA093FF, $_GuiCountDown )
            EndIf
        EndIf
    EndIf
EndFunc ;==> _Check ( )

Share this post


Link to post
Share on other sites

Posted

thank You :unsure::>

Share this post


Link to post
Share on other sites

Posted

thank You :unsure::>

Is it as you like ? Posted Image

Share this post


Link to post
Share on other sites

Posted

hey wakillon, the script that you posted doesnt have hours the script only has Minutes and seconds...

Share this post


Link to post
Share on other sites

Posted

I need a timer HH:MM:SS

Hours:Minutes:Seconds

I am going to build a client timer software for computer shops I mean a cafeagent like software... using autoit...

Share this post


Link to post
Share on other sites

Posted

Try understanding the script and it should be easy to adapt.

Share this post


Link to post
Share on other sites

Posted

GianAutoitprogrammer,

So far you have been "GianAutoitASKER" - this forum is not a request shop for everything you want in AutoIt. We expect YOU to do some of the work yourself. :>

wakillon has very kindly given you a a good chunk of code (as have others in other threads, including myself) - it is now up to YOU to develop those snippets. We are here to help you when you run into problems, but we are NOT here to write your code for you.

I would suggest you take a little time to learn a bit about AutoIt. Reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page). There are even video tutorials on YouTube if you prefer watching to reading.

So over to you. Start writing your own scripts and you will find us ready and willing to help - keep asking for code and you will soon find that no-one will answer.

Your choice! :unsure:

M23

Share this post


Link to post
Share on other sites

Posted

@jos which script wakillon script?

Share this post


Link to post
Share on other sites

Posted

@Melba23 I am helphing others since yesterday iam viewing the Genral help and Support and searching for the problems that I can solve... Sorry if I am asking too much :unsure:

I am just in a hurry...

Share this post


Link to post
Share on other sites

Posted

@Melba23 I am helphing others since yesterday iam viewing the Genral help and Support and searching for the problems that I can solve... Sorry if I am asking too much :unsure:

I am just in a hurry...

Allez au boulot !

Show us your adaptation of my countdown ! Posted Image

Share this post


Link to post
Share on other sites

Posted

@Melba23 I am using autoit since last year but there are some funcrions that I cant understand so thats why I am asking here... But its okay, i am asking too much...

Share this post


Link to post
Share on other sites

Posted

and who knows I am just a second year high school...

Share this post


Link to post
Share on other sites

Posted

Search the 'Example Scripts' forum section using 'countdown' as the keyword..

Share this post


Link to post
Share on other sites

Posted

@somdcomputerguy I am now searching...

Share this post


Link to post
Share on other sites

Posted

Okay I think I cant create a countdown timer but I can call the sleep() function

Sleep(3600) ; 3600 ms = 1 hr

1hr countdown timer

...

Share this post


Link to post
Share on other sites

Posted

Good step. Read thru all the scripts you find. So while Jos was refering to the code that wakillon posted in this thread to help you, it will surely help you to read thru the many 'countdown' related scripts you will find in the Examples section. Soon the lightbulb above your head will be burning brightly! :>:unsure:

Share this post


Link to post
Share on other sites

Posted (edited)

Read thru the Help file too. Sleep(3600) will 'sleep' for slightly more than 3 and half seconds..They don't teach milliseconds until junior (3rd) year in your high school?<br>

Edited by somdcomputerguy

Share this post


Link to post
Share on other sites

Posted

tnx all of you for helping me :unsure:

Share this post


Link to post
Share on other sites

Posted (edited)

Have a look here:

Br,

UEZ

Edited by UEZ

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