arminius Posted March 28, 2008 Share Posted March 28, 2008 ok what I'm trying to do is use a timer to record the time it takes to run a script, and displays the time it took at the end of the script here is a simple version of what I'm trying to achieve. CODE$begin = TimerInit() $dif = TimerDiff($begin) ProgressOn("Progress Meter", "Increments every second", "0 percent") For $i = 10 to 100 step 10 sleep(1000) ProgressSet( $i, $i & " percent") Next ProgressSet(100 , "Done", "took $dif hours/mins") sleep(5000) ProgressOff() so $dif is the timer value I belive? I wrote $dif at progress set 100 near the bottom, but as u can guess it just said $dif instead of the around 12 seconds it took. so anyone got any advice? Link to comment Share on other sites More sharing options...
Swift Posted March 28, 2008 Share Posted March 28, 2008 (edited) ok what I'm trying to do is use a timer to record the time it takes to run a script, and displays the time it took at the end of the script here is a simple version of what I'm trying to achieve. CODE$begin = TimerInit() $dif = TimerDiff($begin) ProgressOn("Progress Meter", "Increments every second", "0 percent") For $i = 10 to 100 step 10 sleep(1000) ProgressSet( $i, $i & " percent") Next ProgressSet(100 , "Done", "took $dif hours/mins") sleep(5000) ProgressOff() so $dif is the timer value I belive? I wrote $dif at progress set 100 near the bottom, but as u can guess it just said $dif instead of the around 12 seconds it took. so anyone got any advice? You need to have the $dif at the bottom. $begin = TimerInit() ProgressOn("Progress Meter", "Increments every second", "0 percent") For $i = 10 to 100 step 10 sleep(1000) ProgressSet( $i, $i & " percent") Next $dif = TimerDiff($begin) ProgressSet(100 , "Done", "took "& $dif &" hours/mins") sleep(5000) ProgressOff() Edited March 28, 2008 by R6V2 Link to comment Share on other sites More sharing options...
arminius Posted March 28, 2008 Author Share Posted March 28, 2008 You need to have the $dif at the bottom. $begin = TimerInit() ProgressOn("Progress Meter", "Increments every second", "0 percent") For $i = 10 to 100 step 10 sleep(1000) ProgressSet( $i, $i & " percent") Next $dif = TimerDiff($begin) ProgressSet(100 , "Done", "took "& $dif &" hours/mins") sleep(5000) ProgressOff() that's great guy thanks, but while I still got ya, it's bringing out a huge amount of digits I don't need, any advice on how to cut it down to just the few seconds it's ment to represent? Link to comment Share on other sites More sharing options...
Swift Posted March 28, 2008 Share Posted March 28, 2008 Yeah, It's because TimerDiff, brings out every digit it can... Use this to cut it down. $begin = TimerInit() ProgressOn("Progress Meter", "Increments every second", "0 percent") For $i = 10 to 100 step 10 sleep(1000) ProgressSet( $i, $i & " percent") Next $dif = TimerDiff($begin) $Time = StringFormat("%.2f", $dif) ProgressSet(100 , "Done", "took "& $time &" hours/mins") sleep(5000) ProgressOff() How bout that? It will shorten it so it only displays like: 1.20 seconds. Link to comment Share on other sites More sharing options...
arminius Posted March 28, 2008 Author Share Posted March 28, 2008 Yeah, It's because TimerDiff, brings out every digit it can... Use this to cut it down. $begin = TimerInit() ProgressOn("Progress Meter", "Increments every second", "0 percent") For $i = 10 to 100 step 10 sleep(1000) ProgressSet( $i, $i & " percent") Next $dif = TimerDiff($begin) $Time = StringFormat("%.2f", $dif) ProgressSet(100 , "Done", "took "& $time &" hours/mins") sleep(5000) ProgressOff() How bout that? It will shorten it so it only displays like: 1.20 seconds. thanks that helped alot, but it's still displaying it in microseconds, do u know how to tell it to divide by a 1000, I'm not familer with this coding your using, if I need to bone up on it any idea where I can go to read? Link to comment Share on other sites More sharing options...
Swift Posted March 28, 2008 Share Posted March 28, 2008 (edited) thanks that helped alot, but it's still displaying it in microseconds, do u know how to tell it to divide by a 1000, I'm not familer with this coding your using, if I need to bone up on it any idea where I can go to read? im not familer with StringFormat either, but you can do: $begin = TimerInit() ProgressOn("Progress Meter", "Increments every second", "0 percent") For $i = 10 to 100 step 10 sleep(1000) ProgressSet( $i, $i & " percent") Next $dif = TimerDiff($begin) $Time = StringFormat("%.2f", $dif) $Time=$Time/1000 $Actual = Round($Time, 0) ProgressSet(100 , "Done", "took "& $Actual &" hours/mins") sleep(5000) ProgressOff() If you really wanted to get accurate, you could read-up on the function StringFormat() which is huge, and I don't understand it, but good luck! Edited March 28, 2008 by R6V2 Link to comment Share on other sites More sharing options...
arminius Posted March 28, 2008 Author Share Posted March 28, 2008 im not familer with StringFormat either, but you can do: $begin = TimerInit() ProgressOn("Progress Meter", "Increments every second", "0 percent") For $i = 10 to 100 step 10 sleep(1000) ProgressSet( $i, $i & " percent") Next $dif = TimerDiff($begin) $Time = StringFormat("%.2f", $dif) $Time=$Time/1000 $Actual = Round($Time, 0) ProgressSet(100 , "Done", "took "& $Actual &" hours/mins") sleep(5000) ProgressOff() If you really wanted to get accurate, you could read-up on the function StringFormat() which is huge, and I don't understand it, but good luck! perfect, thanks mate your tops, I nearly had another question when I went to test it by changing the sleep from 1000 to 2000 to see if the timer would change it's value, and was confused when the total time doubled, until I realised it was adding an extra second to every 10 cycles, I'm such a newb, but yeah I added sleeps elsewhere and it worked perfectly, so kudos 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