zxcvbnm Posted January 9, 2011 Posted January 9, 2011 I'm new user of autoit, I've to implement a simple 5 minutes countdown... it is possible?
zxcvbnm Posted January 9, 2011 Author Posted January 9, 2011 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...
Mat Posted January 9, 2011 Posted January 9, 2011 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 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. AutoIt Project Listing
JohnOne Posted January 9, 2011 Posted January 9, 2011 Change them to AdlibRegister, and AdlibUnRegister, respectively. Also look at the forum wiki where you will find some tutorials for beginners. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Darknight1366 Posted January 9, 2011 Posted January 9, 2011 ;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
Kalin Posted January 9, 2011 Posted January 9, 2011 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.
zxcvbnm Posted January 9, 2011 Author Posted January 9, 2011 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!
Mat Posted January 9, 2011 Posted January 9, 2011 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 #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 AutoIt Project Listing
zxcvbnm Posted January 9, 2011 Author Posted January 9, 2011 Thanks a lot! good start point...I keep working on!
zxcvbnm Posted January 10, 2011 Author Posted January 10, 2011 now I have this: expandcollapse popup#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
Mat Posted January 10, 2011 Posted January 10, 2011 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 AutoIt Project Listing
zxcvbnm Posted January 11, 2011 Author Posted January 11, 2011 Thanks! I do it: while 1 GuiCtrlSetColor($Label, 0xFF0000) Sleep(1000) GuiCtrlSetColor($Label, 0x000000) Sleep(1000) WEnd Can you delete the icon near the clock while running the executable?
somdcomputerguy Posted January 11, 2011 Posted January 11, 2011 (edited) Can you delete the icon near the clock while running the executable?This may help, see TrayIconHide in the Helpfile. Edited January 11, 2011 by somdcomputerguy - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
somdcomputerguy Posted January 11, 2011 Posted January 11, 2011 You bet. Good luck. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
zxcvbnm Posted January 11, 2011 Author Posted January 11, 2011 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 )
zxcvbnm Posted January 11, 2011 Author Posted January 11, 2011 The only way to make windows dragable is this one? While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_PRIMARYDOWN _SendMessage($frmMain, $WM_SYSCOMMAND, 0xF012, 0) EndSwitch WEnd
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