I want to create a time difference measurement system, and I'm thinking GetTickCount or timeGetTime would be good for this. A simple technique would be like:
Problem is when A is just before &h80000000 and B is just after &h80000000, then you have A which is a really large positive number and B which is a really large negative number, such that when you subtract B from A you get a REALLY REALLY REALLY big negative number that will overflow. I have fixed this problem of signed numbers by using this below code to force them to be unsigned numbers:
This will now work for all situations except one. And that is if there is a timer rollover between the code A=GetTickCount (or A=timeGetTime) and the code B=GetTickCount (or B=timeGetTime). In this case A will be larger than B, rather than B being larger than A. If this happens (though rare, I don't want my program to appear to randomly crash for unknown reasons as a result of this bug) then the result will be a large negative number. For example A = unsigned value &hFFFFFFFF (4294967295) and B = unsigned value &h00000000 (0) and you subtract A from B you end up with the negative number -&hFFFFFFFF (-4294967295).
Yet the fact the value that SHOULD be recorded is 1 (not -4294967295), as 0 after rollover is occurs 1 tick (or millisecond) AFTER 4294967295 ticks (or milliseconds). So I need to know how to compensate for this rollover. According to an article I read at http://blogs.msdn.com/b/sloh/archive...05/405724.aspx this rollover compensation theoretically happens automatically such that 0x200 - 0xFFFFFF00 = 0x300 (768). However I find that this is NOT true. In my own experience, using the above code (and manually setting A and B, in order to guaranty a rollover, and using the exact values in the web article in question), I end up with 0x200 - 0xFFFFFF00 = -4294966528
I would LOVE to know how to get it to work. But I CONSISTENTLY end up with it not working.
Can somebody tell me how to make a "timer difference" mechanism that works for the rare (but possible) situation in which value A is a few milliseconds before rollover, and value B is a few milliseconds after rollover?
Code:
Dim A as Long
Dim B as Long
'Elsewhere in the code I've already declared GetTickCount or timeGetTime
A = GetTickCount 'or timeGetTime
'do some stuff here
B = GetTickCount 'or timeGetTime
Print B - A
Code:
Dim A as Long
Dim B as Long
Dim A2 as Currency
Dim B2 as Currency
'Elsewhere in the code I've already declared GetTickCount or timeGetTime
A = GetTickCount 'or timeGetTime
'do some stuff here
B = GetTickCount 'or timeGetTime
'Elsewhere in the code I've already declared CopyMemory
CopyMemory A2, A, 4
CopyMemory B2, B, 4
Print B*10000 - A*10000
Yet the fact the value that SHOULD be recorded is 1 (not -4294967295), as 0 after rollover is occurs 1 tick (or millisecond) AFTER 4294967295 ticks (or milliseconds). So I need to know how to compensate for this rollover. According to an article I read at http://blogs.msdn.com/b/sloh/archive...05/405724.aspx this rollover compensation theoretically happens automatically such that 0x200 - 0xFFFFFF00 = 0x300 (768). However I find that this is NOT true. In my own experience, using the above code (and manually setting A and B, in order to guaranty a rollover, and using the exact values in the web article in question), I end up with 0x200 - 0xFFFFFF00 = -4294966528
I would LOVE to know how to get it to work. But I CONSISTENTLY end up with it not working.
Can somebody tell me how to make a "timer difference" mechanism that works for the rare (but possible) situation in which value A is a few milliseconds before rollover, and value B is a few milliseconds after rollover?