As most people discover or learn, GetTickCount can be used to determine the system uptime. Those of us who are more devout computer users also discover that after about 25 days, it breaks. Even if you convert the Long to unsigned, it still breaks after around 50 days. Because of this, I have created a function that I call GetTickDouble.
'Declares
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
Public Declare Function GetTickCount Lib "kernel32" () As Long
'Code
Public Function GetTickDouble() As Double
Dim Cou As Currency
Dim Fre As Currency
On Error GoTo Erred
If QueryPerformanceCounter(Cou) And QueryPerformanceFrequency(Fre) Then
GetTickDouble = Int(Cou / Fre * 1000)
Else
GetTickDouble = LongToUnsigned(GetTickCount)
End If
Exit Function
Erred:
GetTickDouble = 0
End Function
Private Function LongToUnsigned(Value As Long) As Double
If Value < 0 Then
LongToUnsigned = Value + 4294967296#
Else
LongToUnsigned = Value
End If
End Function
Explanation:
QueryPerformanceCounter and QueryPerformanceFrequency are high quality timer APIs that allow for microsecond counting (6 decimals down from seconds). They're much more accurate at getting times. However, there is a problem with them if you have an older Dual Core processor and haven't installed the correct patch (Google it for more info). Not all OSs support QueryPerformance stuff, so I added GetTickCount and converted it to an Unsigned value just in case. As for the Currency types: QueryPerformance actually uses the Large_Integer type, but in VB6 you can use Currency instead so you don't have to deal with converting the LargeIntegers into a format you can use.
Quite a few people don't know about it, sorry for trying to be helpful.
Don't discourge Ripple when he does something productive.
Nice job.
Is this code PowerBASIC optimised?
PB can handle 64 bit and unsigned variables just fine, has an entirely different error handling system, declares APIs automatically, etc... In PB, this entire thing would be much, much easier.
AH I C WHAT U DID THAR
Quote from: devcode on October 20, 2007, 09:26 PM
Quote from: squiggly on October 20, 2007, 04:27 PM
Quote from: squiggly on October 20, 2007, 03:54 PM
Guess who doesn't care
/me raises hand
QPC is soooo 1992
lol.
Yeah, TS, this is extremely old to most of us (pretty much everyone) but thanks and good job anyhow
Thanks Reality! :)