There are a number of API which you may find useful.
Among them are
GetLocalTime and
GetSystemTime
here is an example of GetSystemTime
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Sub Form_Load()
Dim SysTime As SYSTEMTIME
GetSystemTime SysTime
Debug.Print "The System Date is:" & SysTime.wMonth & "-" & SysTime.wDay & "-" & SysTime.wYear
End Sub
and you can reference any value in the SYSTEMTIME structure
Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
"Only???" That is an eternity! Is there no way to do better than 55ms precision? That would be a major disappointment. Oh why couldn't my predecessor have created this app in VC++?
CajunC, you may remember me from last week. I am still trying to create a more accurate timer, hence this thread. I plan, as I think you suggested, to get the system time at the beginning and end of my timer event code and then to subtract the event execution time from the subsequent timer interval. So, in other words, the interval would be adaptively set depending on how long it takes to execute the timer event.
The basic problem revolves around two things which are essetially outside of the programmer's control. The first is the CMOS clock itself, which generally cycles 18.2 times per second - that is approx 54.9 ms. Add to that the overhead that Windows needs to process and deliver the appropriate messages as strongm has already indicated, your precision can't get much better than that.
If you dropped into assembler, you may be able to circumvent some of the Windows overhead, but unless you have some special purpose timer hardware, I don't know of a way to substantially decrease the timer interval.
Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
Ok - now we've established that you really do want a higher resolution timer than the system time, try the following: [tt]
Option Explicit
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
Private Sub Timed_Procedure()
Dim startticks As Currency
Dim endticks As Currency
Dim frequency As Currency
QueryPerformanceFrequency frequency ' ticks per second. Guaranteed not to change once machine is booted, but may differ slightly with each reboot. Don't hardcode
QueryPerformanceCounter startticks
' stuff you want to time
QueryPerformanceCounter endticks
MsgBox (endticks - startticks) / frequency ' elapsed time in seconds...
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.