Log in

View Full Version : Timer - Help needed


sakanabar
06-20-2003, 12:42 AM
Hi,

I am trying to make a timer in eVB. I have the timer increasing from 0 to 100000msec. Now inorder to present it as text (minute:second:millisec), I need to extract the last 3 digits (<--- how do i do that?) and give the condition,

if millisec is> 999, increase second by one

and extract middle 2 digits and provide conditions

if second is >59 then increase the minute

I do not know how to extract the last digits from the timer.
I this the only way the time can be displayed or is there a more simpler way. I do need to accuracy of atleast 10msec. Thanks

Any suggestions/comments will be appreciated.

oe1kenobi
06-20-2003, 04:48 AM
I don't do hardly any VB programming, so I'm not sure what the best way to do this is, but here I go.
(1) to get the last 3 digits of a number, use the modulus operation. (% in C, might be MOD() in VB).
If you aren't familiar with it: it is the "remainder" function, so:
100 % 10 = 0
101 % 10 = 1
...
109 % 10 = 9
110 % 10 = 0
etc.
So, for just the last 3 digits of a number:
msec = timer % 1000

(2) This REALLY isn't the way you want to go anyway. Timers are not very precise, so if you actually want to be accurate use something like GetTickCount() instead. In eVC++, I record the starting tick count, then calculate the elapsed time as:
Minutes = (TickStart - TickCurrent) / 60000
(note this is integer division, which I'm note sure VB will do. You might need to use something like truncate or whatever to take the integer portion of the result).
Seconds = ((TickStart - TickCurrent) % 60000) / 1000.0
(note this is floating-point division, so you get 15.23 seconds etc.)

In general, just record the starting time and ending time and only rely on timers to call the update for the display. Don't try and increment counters or you will really lose accuracy. I'm not sure what function in eVB you can use to get your current time accurately.

Good luck.

-Richard L. Owens
eVC++ hobbyist