zvd Posted January 10, 2007 Posted January 10, 2007 Can't seem to make this countdown timer work properly. In the present state it only counts down 1 or two second with every push of the button. I'd like it to run fully with one push... I've tried a do loop, but then the Label1 gets all messed up! #include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("TeaTime", 163, 147, 193, 115) $Label1 = GUICtrlCreateLabel("5 Minute Tea Timer", 24, 16, 114, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Label1 = GUICtrlCreateLabel("5:00", 56, 48, 49, 33) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") $Button1 = GUICtrlCreateButton("Start", 24, 96, 49, 17, 0) $Button2 = GUICtrlCreateButton("Exit", 88, 96, 49, 17, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $time=TimerInit() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 Exit Case $Button1 $new = TimerDiff ($time) $new = (5*60*1000)-$new $seconds = Round ($new/1000) $newMin = Floor ($seconds/60) $newSec = Mod ($seconds, 60) If $newSec < 10 Then $newSec = "0"&$newSec GUICtrlSetData ($Label1, $newMin&":"&$newSec) EndSwitch WEnd
RazerM Posted January 10, 2007 Posted January 10, 2007 expandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("TeaTime", 163, 147, 193, 115) $Label1 = GUICtrlCreateLabel("5 Minute Tea Timer", 24, 16, 114, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Label1 = GUICtrlCreateLabel("5:00", 56, 48, 49, 33) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") $Button1 = GUICtrlCreateButton("Start", 24, 96, 49, 17, 0) $Button2 = GUICtrlCreateButton("Exit", 88, 96, 49, 17, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $timer, $bCountdown = False While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 Exit Case $Button1 $bCountdown = True $timer = TimerInit() EndSwitch If $bCountdown Then UpdateTimer() WEnd Func UpdateTimer() $new = TimerDiff($timer) $new = (0.1 * 60 * 1000) - $new $seconds = Round($new / 1000) $newMin = Floor($seconds / 60) $newSec = Mod($seconds, 60) If $newSec < 10 Then $newSec = "0" & $newSec If $newMin & ":" & $newSec = "0:00" Then $bCountdown = False GUICtrlSetData($Label1, $newMin & ":" & $newSec) EndFunc ;==>UpdateTimer Hope that helps. The code could be optimized but you get the idea. Also, use [ autoit] and [ /autoit] tags around your code (without the spaces). My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now