PDA

Click to See Complete Forum and Search --> : Signed/Unsigned numbers in VB (Using GetTickCount)


Chill
Jan 14th, 2000, 03:46 AM
I have some simple code I'm porting from C to VB. It basically is going to take the number of milliseconds as an argument and pause for that amount of time. My problem is that VB doesn't appear to support unsigned longs, therefor my algorithm interprets the big unsigned as a negative and doesn't work right... I know I can rewrite it to use if base < timer and fix it, but is there a simpler way in VB? (I know I could use the timer control or a call to sleep in the SDK, but for various reasons I'd like to do it this way). Here's what I'm writing:

Private Declare Function GetTickCount Lib "kernel32" () As Long
Public Sub sleep(milliseconds As Long)
Dim timer As Long
Dim basetime As Long

basetime = GetTickCount
Do
timer = GetTickCount
DoEvents: DoEvents: DoEvents: DoEvents: DoEvents
Loop Until Abs(timer) - Abs(basetime) < milliseconds
End Sub

It'll work unless your system has been running for a long time and the long returned which is really unsigned get's interpreted as a negative.

Thanks,
Chris Hill