[RESOLVED] why overflow error on WinMe ?
VB Code:
Private Const WaitTime = 150
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Declare Function GetTickCount Lib "winmm.dll" Alias "timeGetTime" () As Currency
Private Const TC As Long = 10000
Public Sub Wait(ByVal dwMilliseconds As Long)
Dim i As Long, zz As Currency
If dwMilliseconds = 0 Then Exit Sub
i = dwMilliseconds
zz = GetTickCount * TC
Do
Sleep WaitTime
i = i - WaitTime
DoEvents
Loop Until (i < (WaitTime / 2)) And (((GetTickCount * TC) - zz) >= dwMilliseconds)
End Sub
on a P4 with WinXP : work fine
on a Celeron 600 with Win2K : work fine
on a P3 with WinMe : overflow error
why i get overflow error on WinMe ?
Re: why overflow error on WinMe ?
Why oh why are you using timeGetTime()? Use the real GetTickCount().
VB Code:
Public Declare Function GetTickCount Lib "kernel32" () As Long
Re: why overflow error on WinMe ?
You'll get an Overflow error because your API call is wrong.
VB Code:
Private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
It returns a Long not Currency. ;)
Re: why overflow error on WinMe ?
Quote:
Originally Posted by Keithuk
You'll get an Overflow error because your API call is wrong.
VB Code:
Private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
It returns a Long not Currency. ;)
Do my eyes deceive me, or is that not exactly what I posted...?
Although, you are correct about timeGetTime() returning a Long.
Re: why overflow error on WinMe ?
Quote:
Originally Posted by penagate
Do my eyes deceive me, or is that not exactly what I posted...?
Although, you are correct about timeGetTime() returning a Long.
You posted right.... it was the OP that had currency as the return type.
-tg
Re: why overflow error on WinMe ?
http://msdn.microsoft.com/library/de...imegettime.asp
Quote:
DWORD timeGetTime(VOID);
The return value wraps around to 0 every 2^32 milliseconds
but there is no unsigned type in vb, so i have to use currency
(5 PC we will probably never reboot them and i dont want negative value)
Re: why overflow error on WinMe ?
Quote:
Originally Posted by penagate
Do my eyes deceive me, or is that not exactly what I posted...?
I know you posted that but you didn't say why he would received an Overflow error. ;)
Quote:
Originally Posted by sergelac
but there is no unsigned type in vb, so i have to use currency
But there is a signed type Long.
Re: why overflow error on WinMe ?
found a solution : no currency and no negative value
Quote:
Originally Posted by OnErr0r
You can use another method which simply shifts the number of ticks right by one. Then the number is always positive. You also get away from the 64 bit math.
VB Code:
'Private Const WAITTIME As Long = 150
'Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Public Sub Wait(ByVal dwMilliseconds As Long)
Dim z As Long, zz As Long ', i As Long
If dwMilliseconds < 5 Then Exit Sub
' i = dwMilliseconds
dwMilliseconds = dwMilliseconds \ 2
z = ((timeGetTime And &HFFFFFFFE) \ 2) And &H7FFFFFFF
Do
' Sleep2 WaitTime
' i = i - WaitTime
DoEvents
' If i < (WaitTime / 2) Then
zz = ((timeGetTime And &HFFFFFFFE) \ 2) And &H7FFFFFFF
If ((zz - z) >= dwMilliseconds) Or (zz < z) Then Exit Do
' End If
Loop
End Sub