Re: gettickcount returns a negative number???

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



pithhelmet wrote:
> My application uses gettickcount to build a unique string
> that is used to communicate with a host system.

Use Hex$(GetTickCount()) instead, in that case. Keep reading if you care why I say
that.

> everything works fine but now i'm receiving a negative
> number from the API call when the system passes the x number of
> days mark....
>
> i tried to recreate the problem using a loop in VB6
> but the program errors out OK when it goes too far -
>
> so why does the API return a negative number?

It doesn't. But that's how VB, and you, choose to view it. Yes, it's a choice. VB
Long variables use the highest bit to indicate sign. But Windows is handing you an
unsigned DWORD value. So, if the highbit is set, VB thinks it's negative. It's up
to you to see beyond that.

&h00000000-&h7FFFFFFF "positive"
&h80000000-&hFFFFFFFF "negative"

If you really gotta have it in decimal, rather than hex, you can "convert" it like
this:

Private Function ULong(ByVal Int32 As Long) As Currency
Const OFFSET_4 As Currency = 4294967296@
If Int32 < 0 Then
ULong = CCur(Int32) + OFFSET_4
Else
ULong = Int32
End If
End Function

Later... Karl
--
Working Without a .NET?
http://classicvb.org/petition


.



Relevant Pages

  • Re: gettickcount returns a negative number???
    ... Have you considered using QueryPerformanceCounter? ... > that is used to communicate with a host system. ... > so why does the API return a negative number? ... > the documentation states gettickcount will return a zero ...
    (microsoft.public.vb.winapi)
  • Re: gettickcount returns a negative number???
    ... >> My application uses gettickcount to build a unique string ... >> that is used to communicate with a host system. ...
    (microsoft.public.vb.winapi)
  • Re: gettickcount returns a negative number???
    ... > My application uses gettickcount to build a unique string ... > that is used to communicate with a host system. ... What about using CoCreateGUID() from OLE32.DLL (or, with NT/XP only, ...
    (microsoft.public.vb.winapi)