I'm working on a small application that needs to maintain accurate time - the reason being, is this application actually allows different functionality based on the current time of day.
I've created 4 Global Values:
Global_HundSecs
Global_Seconds
Global_Minutes
Global_Hours
At the start of the application, I set the above Global Values to retrieve their respective value from the Date/Time object.
This stamps the application with the exact time that the application was started.
From that point on, I've setup a timer and some variables to keep the time going - that way I don't have to constantly ask the Date/Time object what time it is.
Something to the effect of:
Every 1/100 of a second, add 1 to Global_HundSecs.
If Global_HundSecs = 100, add 1 to Global_Seconds, and set Global_HundSec to 0.
If Global_Seconds = 60, add 1 to Global_Minutes, and set Global_Seconds to 0.
If Global_Minutes = 60, add 1 to Global_Hours, and set Global_Minutes to 0.
If Global_Hours = 25, set Global_Hours to 0.
So, the above code should keep the time going.
To test my code to make sure it works accurately, I test the current in-app time agains the current system time retrieved from the Date/Time object.
The calculations are off - making my in-app clock run slower than my system clock.
Any thoughts?