Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

How to create a countdown timer in autoit?


  • Please log in to reply
38 replies to this topic

#1 GianAutoitprogrammer

GianAutoitprogrammer

    Wayfarer

  • Active Members
  • Pip
  • 85 posts

Posted 16 April 2011 - 08:35 AM

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
AutoIt         
#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, 16 April 2011 - 08:36 AM.








#2 wakillon

wakillon

    Tiny Tools Coder

  • Active Members
  • PipPipPipPipPipPip
  • 2,867 posts

Posted 16 April 2011 - 08:58 AM

An example :

AutoIt         
#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 Version : 3.3.12.0 / Beta 3.3.13.19 SciTE 3.4.1 OS:WIN7/WIN8.1 CPU:X64 OS:X64


#3 GianAutoitprogrammer

GianAutoitprogrammer

    Wayfarer

  • Active Members
  • Pip
  • 85 posts

Posted 16 April 2011 - 09:14 AM

thank You :unsure: :>

#4 wakillon

wakillon

    Tiny Tools Coder

  • Active Members
  • PipPipPipPipPipPip
  • 2,867 posts

Posted 16 April 2011 - 09:19 AM

thank You :unsure: :>


Is it as you like ? Posted Image

       AutoIt Version : 3.3.12.0 / Beta 3.3.13.19 SciTE 3.4.1 OS:WIN7/WIN8.1 CPU:X64 OS:X64


#5 GianAutoitprogrammer

GianAutoitprogrammer

    Wayfarer

  • Active Members
  • Pip
  • 85 posts

Posted 16 April 2011 - 09:23 AM

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

#6 GianAutoitprogrammer

GianAutoitprogrammer

    Wayfarer

  • Active Members
  • Pip
  • 85 posts

Posted 16 April 2011 - 09:33 AM

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

#7 Jos

Jos

    ...

  • Developers
  • 23,289 posts

Posted 16 April 2011 - 09:35 AM

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

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#8 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,466 posts

Posted 16 April 2011 - 09:40 AM

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
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#9 GianAutoitprogrammer

GianAutoitprogrammer

    Wayfarer

  • Active Members
  • Pip
  • 85 posts

Posted 16 April 2011 - 09:40 AM

@jos which script wakillon script?

#10 GianAutoitprogrammer

GianAutoitprogrammer

    Wayfarer

  • Active Members
  • Pip
  • 85 posts

Posted 16 April 2011 - 09:45 AM

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

#11 wakillon

wakillon

    Tiny Tools Coder

  • Active Members
  • PipPipPipPipPipPip
  • 2,867 posts

Posted 16 April 2011 - 09:48 AM

@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 Version : 3.3.12.0 / Beta 3.3.13.19 SciTE 3.4.1 OS:WIN7/WIN8.1 CPU:X64 OS:X64


#12 GianAutoitprogrammer

GianAutoitprogrammer

    Wayfarer

  • Active Members
  • Pip
  • 85 posts

Posted 16 April 2011 - 09:50 AM

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

#13 GianAutoitprogrammer

GianAutoitprogrammer

    Wayfarer

  • Active Members
  • Pip
  • 85 posts

Posted 16 April 2011 - 09:52 AM

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

#14 somdcomputerguy

somdcomputerguy

  • Active Members
  • PipPipPipPipPipPip
  • 2,852 posts

Posted 16 April 2011 - 09:54 AM

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

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


#15 GianAutoitprogrammer

GianAutoitprogrammer

    Wayfarer

  • Active Members
  • Pip
  • 85 posts

Posted 16 April 2011 - 09:58 AM

@somdcomputerguy I am now searching...

#16 GianAutoitprogrammer

GianAutoitprogrammer

    Wayfarer

  • Active Members
  • Pip
  • 85 posts

Posted 16 April 2011 - 10:09 AM

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

#17 somdcomputerguy

somdcomputerguy

  • Active Members
  • PipPipPipPipPipPip
  • 2,852 posts

Posted 16 April 2011 - 10:09 AM

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.


#18 somdcomputerguy

somdcomputerguy

  • Active Members
  • PipPipPipPipPipPip
  • 2,852 posts

Posted 16 April 2011 - 10:11 AM

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, 16 April 2011 - 10:15 AM.

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


#19 GianAutoitprogrammer

GianAutoitprogrammer

    Wayfarer

  • Active Members
  • Pip
  • 85 posts

Posted 16 April 2011 - 10:36 AM

tnx all of you for helping me :unsure:

#20 UEZ

UEZ

    Never say never

  • MVPs
  • 4,888 posts

Posted 16 April 2011 - 01:12 PM

Have a look here: http://www.autoitscript.com/forum/topic/126449-gui-with-button-and-countdown-and-auto-restore/page__p__878345#entry878345

Br,
UEZ

Edited by UEZ, 16 April 2011 - 01:13 PM.

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users