Jump to content
Sign in to follow this  
GianAutoitprogrammer

How to create a countdown timer in autoit?

Recommended Posts

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

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 ( )

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

@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


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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:


- 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

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

- 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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...