logcomptechs Posted January 19, 2009 Share Posted January 19, 2009 I would like to know how to create a timer that will keep track of the time that the script has been running for, in hours, minutes, and seconds. Basically just start from zero and keep counting up in hours, minutes, seconds, until the script is turned off. Thanks for the Help! Link to comment Share on other sites More sharing options...
Orgins Posted January 19, 2009 Share Posted January 19, 2009 (edited) Look up TimerInit() and TimerDiff() in the readme/help file. That'll get you started. /edit Basic exp: $begin = TimerInit() While 1 $dif = TimerDiff($begin) $secs = $dif/1000 $mins = $secs/60 $hours = $mins/60 Tooltip("hours " & Int($hours) & " mins " & Int($mins) & " secs " & Int($secs),50,50) wend O/c this doesn't work right. The secs/mins wont roll over at 2 mins it'll be 2mins 120 secs and at 2 hours it'll be 2 hours 120 mins xxxxx secs and so on. It won't take much work to fix/recode this but you should do it if you wana learn. Edited January 19, 2009 by Orgins I'm a newbie.Sorry if I don't reposed to your replays very fast. Link to comment Share on other sites More sharing options...
logcomptechs Posted January 19, 2009 Author Share Posted January 19, 2009 (edited) I was already looking at that command, made something similar, but it was flickering and like you said time wasn't rolling over correctly. Thanks for your help, hopefully I can figure out a solid solution. This is my script $begin = TimerInit() While 1 $mil = TimerDiff($begin) $secs = TimerDiff($begin) * 0.001 $mins = TimerDiff($begin) * 0.000016667 $hours = TimerDiff($begin) * 0.000000278 Tooltip("Hours" & @CRLF & Int($hours) & @CRLF & "Minutes" & @CRLF & Int($mins) & @CRLF & "Seconds" & @CRLF & Int($secs),50,50) Wend It flickers and I am not sure how to take care of that. Edited January 19, 2009 by logcomptechs Link to comment Share on other sites More sharing options...
NerdFencer Posted January 19, 2009 Share Posted January 19, 2009 (edited) Here is an example I just wrote for you, It is expanded more than it needs to be to make it easier for you. It also includes a flicker fix. expandcollapse popup;;Create the GUI window GUICreate("Timer",200,25) ;---------------------------- Timer GUI ------------------------------ ;Label for the time GUICtrlCreateLabel("Time Since Script has started:",5,5) ;Place to display the time $TimerTime = GUICtrlCreateLabel("",150,5,100,25) ;Create the timer $Timer = TimerInit() ;Time globals $CurSec = 0 $CurMin = 0 $CurHr = 0 ;Start showing the window GUISetState(@SW_SHOW) ;---------------------------- Main Loop ------------------------------ While Not(GUIGetMsg()==-3) Sleep(2) ;Update the Timer time If Not(GUICtrlRead($TimerTime)==TimerGetStringTime($Timer)) Then GUICtrlSetData($TimerTime,TimerGetStringTime($Timer)) EndIf WEnd ;--------------------- Timer Support Functions ---------------------- ;Note: All of these functions could be condensed into the TimerGetStringTime function, but they are expanded for your benefit Func TimerGetStringTime($hTimer) ;Fix timer flicker $Sec = TimerGetSec($hTimer) $Min = TimerGetMin($hTimer) $Hr = TimerGetHrs($hTimer) If $CurSec<$Sec Or $CurSec-$Sec >50 Then $CurSec = $Sec If $CurMin<$Min Or $CurMin-$Min >50 Then $CurMin = $Min If $CurHr <$Hr Or $CurHr -$Hr >50 Then $CurHr = $Hr ;Return the time Return String($CurHr)&":"&String($CurMin)&":"&String($CurSec) EndFunc Func TimerGetSec($hTimer) $Time = TimerDiff($Timer) ;Get the time from the timer $Time = Int($Time/1000) ;Convert milliseconds to secconds $Time = Mod($Time,60) ;Remove all secconds past 60 Return $Time ;Return the Value EndFunc Func TimerGetMin($hTimer) $Time = TimerDiff($Timer) ;Get the time from the timer $Time = Int($Time/60000) ;Convert milliseconds to minutes $Time = Mod($Time,60) ;Remove all Minutes past 60 Return $Time ;Return the Value EndFunc Func TimerGetHrs($hTimer) $Time = TimerDiff($Timer) ;Get the time from the timer $Time = Int($Time/3600000) ;Convert milliseconds to hours $Time = Mod($Time,24) ;Remove all Minutes past 24 Return $Time ;Return the Value EndFunc Edit: Fixed a slight bug in example Edited January 19, 2009 by NerdFencer _________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell Link to comment Share on other sites More sharing options...
Robjong Posted January 19, 2009 Share Posted January 19, 2009 Hey, For the code above (nice example btw), to make the timer look like 00:00:00 instead of 0:0:0 replace this line... Return String($CurHr)&":"&String($CurMin)&":"&String($CurSec)oÝ÷ ØZ½ëayú%"(ëb¢x«'¢wuú+Zj[ºÚ"µÍÕRPÜX]J ][ÝÕ[Y][ÝÊBÌÍÚX[HÕRPÝÜX]SX[ ][ÝÔÙXÛÛÎ ][ÝËLL BÕRTÙ]Ý]J BÌÍÚU[YH[Y[] HÈÝ[YÚ[HÕRQÙ]ÙÊ H ÉÝÈLÂßWÔÙXÛÛÊ ÌÍÚX[ ÌÍÚU[YBWÕ[Y[YJ ÌÍÚU[Y ÌÍÚX[ BTÛY JBÑ[B[ÈÕ[Y[YJ ÌÍÚU[Y[] ÌÍÚÝHY][ BRYÝÝ[ÒÒ[ ÌÍÚU[Y[] H[]Ù]ÜK BSØØ[ ÌÍÚQYH[YY ÌÍÚU[Y[] BØØ[ ÌÍÚTÙXÜÈH[Ù [ ÌÍÚQYÈL K BBBØØ[ ÌÍÚSZ[H[Ù [ ÌÍÚQYÈ K BBØØ[ ÌÍÚRÝÈH[Ù [ ÌÍÚQYÈÍ K BBBSØØ[ ÌÍÜÕ[YHÝ[ÑÜX] ][ÝÉLLL ][ÝË ÌÍÚRÝË ÌÍÚSZ[ ÌÍÚTÙXÜÊBRY ÌÍÚÝ[ ÌÍÜÕ[Y ÉÝÈÕRPÝXY ÌÍÚÝ H[ÕRPÝÙ]]J ÌÍÚÝ ÌÍÜÕ[YBT] ÌÍÜÕ[Y[[ Link to comment Share on other sites More sharing options...
NerdFencer Posted January 19, 2009 Share Posted January 19, 2009 Hey,For the code above (nice example btw), to make the timer look like 00:00:00 instead of 0:0:0 replace this line...That return line does work, and looks better What the globals in my example are for a workaround for the flicker glitch (which is present in your example)There is a way without globals that I know of, but it is more complex. _________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell Link to comment Share on other sites More sharing options...
Robjong Posted January 19, 2009 Share Posted January 19, 2009 I didnt notice any flickering, but could only bring myself to watch it for 30 secs at a time or so:P anyway your code is more versatile, think the OP should have everything he needs with that Link to comment Share on other sites More sharing options...
logcomptechs Posted January 19, 2009 Author Share Posted January 19, 2009 Thank you all for the great examples. Only issue I am running into now is that I put this inside my already existing While statement, but the timer doesn't start going (assuming cause it has to runt through the entire script to get back to the timer part). But I do need it inside my current While statement, I was trying to use Function, but that was not working as I thought it would. If you have any thoughts, that would be great. Link to comment Share on other sites More sharing options...
FireFox Posted January 19, 2009 Share Posted January 19, 2009 (edited) @logcomptechs Maybe... $init = TimerInit() While 1 $diff = TimerDiff($init) TrayTip('Timer', $diff, 0, 1) If $diff >= 5 Then ;restart timer ; Timer() could be used with a func $init = TimerInit() EndIf WEnd Not tested. Cheers, FireFox. Edited January 19, 2009 by FireFox 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