Author | Message | Time |
---|---|---|
Barabajagal | 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. [code] '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[/code] 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. | October 20, 2007, 8:54 PM |
squiggly | [quote author=squiggly link=topic=17124.msg174039#msg174039 date=1192913682] Guess who doesn't care [me=squiggly]raises hand[/me] [/quote] | October 20, 2007, 9:27 PM |
devcode | [quote author=squiggly link=topic=17124.msg174041#msg174041 date=1192915674] [quote author=squiggly link=topic=17124.msg174039#msg174039 date=1192913682] Guess who doesn't care [me=squiggly]raises hand[/me] [/quote] [/quote] QPC is soooo 1992 | October 21, 2007, 2:26 AM |
squiggly | [quote author=devcode link=topic=17124.msg174044#msg174044 date=1192933600] [quote author=squiggly link=topic=17124.msg174041#msg174041 date=1192915674] [quote author=squiggly link=topic=17124.msg174039#msg174039 date=1192913682] Guess who doesn't care [me=squiggly]raises hand[/me] [/quote] [/quote] QPC is soooo 1992 [/quote] What you say there? | October 21, 2007, 2:31 AM |
Barabajagal | Quite a few people don't know about it, sorry for trying to be helpful. | October 21, 2007, 9:12 PM |
Quarantine | Don't discourge Ripple when he does something productive. Nice job. | October 23, 2007, 2:41 AM |
squiggly | Is this code PowerBASIC optimised? | October 23, 2007, 2:42 AM |
Barabajagal | 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. | October 23, 2007, 3:18 AM |
warz | AH I C WHAT U DID THAR | October 24, 2007, 7:04 PM |
UserLoser | [quote author=devcode link=topic=17124.msg174044#msg174044 date=1192933600] [quote author=squiggly link=topic=17124.msg174041#msg174041 date=1192915674] [quote author=squiggly link=topic=17124.msg174039#msg174039 date=1192913682] Guess who doesn't care [me=squiggly]raises hand[/me] [/quote] [/quote] QPC is soooo 1992 [/quote] lol. Yeah, TS, this is extremely old to most of us (pretty much everyone) but thanks and good job anyhow | November 1, 2007, 11:36 PM |
dlStevens | Thanks Reality! :) | November 6, 2007, 1:39 PM |