gottygolly Posted November 16, 2014 Share Posted November 16, 2014 I'm trying to do something where you can have 2 timers running at the same time (in other words, a timer without sleep functions). I thought I found a good way to do it by reading the time on the computer and then some how changing it to 0 and starting it like that, but I ran into a problem. The script below gets the time and everything but for some reason I can't figure out how to make it change with the second. If you start the script it will start at 0 but then itll add up really fast to catch up to the second. Is there anyway to make it not do this and have it just add 1 whenever the second changes? $gui = GUICreate("",300,300,-1,-1) $i = 0 $t = GUICtrlCreateLabel($i,5,5) $ti = 0 GUISetState() While 1 $s = @SEC If $i <> $s Then $i = $i + 1 GUICtrlSetData($t,$i) Sleep(10) EndIf $msg = GUIGetMsg(1) Switch $msg[1] case $gui Switch $msg[0] Case -3 Exit EndSwitch EndSwitch WEnd Thanks in advance for any help! Link to comment Share on other sites More sharing options...
Moderators Solution SmOke_N Posted November 16, 2014 Moderators Solution Share Posted November 16, 2014 (edited) $gui = GUICreate("",300,300,-1,-1) $i = 0 $t = GUICtrlCreateLabel($i,5,5) $ti = 0 Local $s_lastsec = @SEC GUISetState() While 1 $s = @SEC If $s <> $s_lastsec Then $i = $i + 1 GUICtrlSetData($t,$i) $s_lastsec = $s EndIf $msg = GUIGetMsg(1) Switch $msg[1] case $gui Switch $msg[0] Case -3 Exit EndSwitch EndSwitch WEnd Edited November 16, 2014 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
gottygolly Posted November 16, 2014 Author Share Posted November 16, 2014 Thank you. I don't know why I couldn't find this. Link to comment Share on other sites More sharing options...
kylomas Posted November 17, 2014 Share Posted November 17, 2014 using adlib's... expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> local $gui010 = guicreate('Timer Example Using Adlib''s',250,100) guictrlcreatelabel('Click on boxes(s) to start/stop timer(s)',10,10,270,25) local $t1 = guictrlcreatelabel('',30,40,20,20,bitor($ss_sunken,$ss_center)) local $t2 = guictrlcreatelabel('',30,70,20,20,bitor($ss_sunken,$ss_center)) local $s1 = guictrlcreatelabel('Stopped',60,43,100,20) local $s2 = guictrlcreatelabel('Stopped',60,73,100,20) guisetstate() local $on_1 = false, $on_2 = false while 1 switch guigetmsg() case $gui_event_close Exit case $t1 $on_1 = not $on_1 if $on_1 then AdlibRegister('T1',1000) guictrlsetdata($s1,'Started') else AdlibUnRegister('T1') guictrlsetdata($s1,'Stopped') endif case $t2 $on_2 = not $on_2 if $on_2 then AdlibRegister('T2',1000) guictrlsetdata($s2,'Started') else AdlibUnRegister('T2') guictrlsetdata($s2,'Stopped') endif EndSwitch WEnd func T1() local static $sec_cnt = 1 guictrlsetdata($t1,$sec_cnt) $sec_cnt += 1 endfunc func T2() local static $sec_cnt = 1 guictrlsetdata($t2,$sec_cnt) $sec_cnt += 1 endfunc Hmmm...nothing like post-football boredom... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
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