Results 1 to 6 of 6

Thread: Need help re-coding small function, and "Error trapping"

  1. #1

    Thread Starter
    Addicted Member Jazz00006's Avatar
    Join Date
    Feb 2006
    Posts
    185

    Need help re-coding small function, and "Error trapping"

    Ok, first off, this code

    Code:
    Public Function Wait(TimeOut As Long)
      Dim TimeNow As Long  
      TimeNow = timeGetTime()
      Do
        DoEvents
      Loop While TimeNow + TimeOut > timeGetTime()
    End Function
    (Not my code, etc)


    Does a wait function for "TimeOut" Milliseconds, but it also (because of doevents) creates lag (CPU Usage) on the computer its running on.

    While this function is only used every now and again, for short periods of time, I was wondering if there was a better way to code this.




    I was also wondering if there was a known way of detecting any errors that happen on the system (from any other program), to be specific, the msgbox style ones.. (Does this make sense?)

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Need help re-coding small function, and "Error trapping"

    Is timeGetTime() an aliased GetTickCount() API?

    You an lessen DoEvents call with Mod:
    If TimeNow Mod 10000 = 0 Then DoEvents

    Or you can try using Sleep API to wait

  3. #3

    Thread Starter
    Addicted Member Jazz00006's Avatar
    Join Date
    Feb 2006
    Posts
    185

    Re: Need help re-coding small function, and "Error trapping"

    using:
    If TimeNow Mod 10000 = 0 Then DoEvents

    cuts down CPU usage by about 10% but using the Sleep API.... cut it down by about 90%
    (Max CPU usage is now about 5)

    Cheers

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

    Re: Need help re-coding small function, and "Error trapping"

    Quote Originally Posted by leinad31
    Is timeGetTime() an aliased GetTickCount() API?
    No .

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Need help re-coding small function, and "Error trapping"

    The Sleep API will actually halt processing. Is this what you are after?

  6. #6

    Thread Starter
    Addicted Member Jazz00006's Avatar
    Join Date
    Feb 2006
    Posts
    185

    Re: Need help re-coding small function, and "Error trapping"

    more or less, just something to pause my program for a short period of time (not doing background processing) so the halting it fine

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