Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[ALL] True fix to getTickCount overlap


Growlith1223
 Share

Recommended Posts

There are various ways of fixing this issue, essentially GetTickCount will overlap into the negatives after a certain amount of time has passed(i can't remember the exact amount of days, but Long is 2.14 billion, and that goes by within like, i believe a week or 2)

There's also timeGetTime, which will get you a longer duration before the value is overlapped to a negative(47 days).

But, there's an even better solution. You'd be losing out on support for Windows XP however as Windows XP does not have support for it.

GetTickCount64. this uses the Currency data type in vb6(ULongLong in C++, ULong in .net), it has a max of 9,223,372,036,854,775,807. which lasts for years.

to use this, simply do
```
Public Declare Function GetTickCount64 Lib "kernel32" () As Currency
Function getTick() As Currency
getTick = GetTickCount64 * 10000
End Function
```
Essentially what this does is, return the value from getTickCount64 * 10000. why the multiplication? the value that is received from GetTickCount64 is a floating point value(a LOT smaller than getTickCount), however, if you mutliply by 10k, it returns a solid value, which is what we need.

You CAN use something like a long at this point, but you'll be getting the same issue again with the rolling over to the negative values.

This essentially solves the issue of trying to handle the rolling over issue, in a few lines of code.

As i said however, you lose the ability to use any program with this code, on Windows XP as WinXP does not have support for it.

Hope this helps!
Link to comment
Share on other sites

GetTickCount returns a DWORD-based value, which is essentially VB6's Long datatype, but still larger since a Dword is an unsigned int. because you can't actually GET an unsigned value in VB6(without some extra maths that i can't think of right now), it's going to overlap regardless of what datatype you use. sure, you could probably divide the Tick count by some value and keep going, but eventually you're still going to hit the limit of Long(or in this case, GetTickCount in general), and overlap into the negatives.

What my code does is get rid of that overlap entirely. Single and Double go nowhere near what the Currency datatype can go to, that and it can actually hold the value that GetTickCount64 provides.

tldr;
GetTickCount will overlap regardless of what you do. GetTickCount64 just holds a LOT larger of a value to prevent this
Link to comment
Share on other sites

Ahh, I gotcha now.

You should also be able to keep track of the number of resets GetTickCount has gone through, then do a bit of math with it:
```
GetTick = GetTickCount + ((MAX_LONG * 2) * TickResetCount) + TickResetCount
```

This is a bit more math, but it does mean you're able to use the Currency type. However, because VB6 has problems with math and overflows, you have to convert the max long to use a currency type, and that has to use `&H7FFFFFFF` as the value since numbers give an error.

I'm going to assume your way is faster/better to use.
Link to comment
Share on other sites

it's less work than keeping track of resets, but yea, i believe you can do it that way if you wanted, it'll just require a tiny bit more processing power

EDIT: Your method's benefit is support for Windows XP and below. Windows XP and below does not have the GetTickCount64 method so it'll just crash on there(if you're worried about WindowXP and below support that is)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...