Results 1 to 8 of 8

Thread: [RESOLVED] why overflow error on WinMe ?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    18

    Resolved [RESOLVED] why overflow error on WinMe ?

    VB Code:
    1. Private Const WaitTime = 150
    2.  
    3. Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    4.  
    5. Private Declare Function GetTickCount Lib "winmm.dll" Alias "timeGetTime" () As Currency
    6. Private Const TC As Long = 10000
    7.  
    8. Public Sub Wait(ByVal dwMilliseconds As Long)
    9.   Dim i As Long, zz As Currency
    10.   If dwMilliseconds = 0 Then Exit Sub
    11.   i = dwMilliseconds
    12.   zz = GetTickCount * TC
    13.   Do
    14.     Sleep WaitTime
    15.     i = i - WaitTime
    16.     DoEvents
    17.   Loop Until (i < (WaitTime / 2)) And (((GetTickCount * TC) - zz) >= dwMilliseconds)
    18. 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 ?

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: why overflow error on WinMe ?

    Why oh why are you using timeGetTime()? Use the real GetTickCount().

    VB Code:
    1. Public Declare Function GetTickCount Lib "kernel32" () As Long

  3. #3
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: why overflow error on WinMe ?

    You'll get an Overflow error because your API call is wrong.
    VB Code:
    1. Private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
    It returns a Long not Currency.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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:
    1. 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.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    18

    Re: why overflow error on WinMe ?

    http://msdn.microsoft.com/library/de...imegettime.asp
    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)
    Last edited by sergelac; Oct 19th, 2005 at 11:33 AM.

  7. #7
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    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.
    Last edited by Keithuk; Oct 19th, 2005 at 02:16 PM.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    18

    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:
    1. 'Private Const WAITTIME As Long = 150
    2.  
    3. 'Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    4. Private Declare Function timeGetTime Lib "winmm.dll" () As Long
    5.  
    6. Public Sub Wait(ByVal dwMilliseconds As Long)
    7.   Dim z As Long, zz As Long ', i As Long
    8.   If dwMilliseconds < 5 Then Exit Sub
    9. '  i = dwMilliseconds
    10.   dwMilliseconds = dwMilliseconds \ 2
    11.   z = ((timeGetTime And &HFFFFFFFE) \ 2) And &H7FFFFFFF
    12.   Do
    13. '    Sleep2 WaitTime
    14. '    i = i - WaitTime
    15.     DoEvents
    16. '    If i < (WaitTime / 2) Then
    17.       zz = ((timeGetTime And &HFFFFFFFE) \ 2) And &H7FFFFFFF
    18.       If ((zz - z) >= dwMilliseconds) Or (zz < z) Then Exit Do
    19. '    End If
    20.   Loop
    21. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width