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?)
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
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 :D
Re: Need help re-coding small function, and "Error trapping"
Quote:
Originally Posted by leinad31
Is timeGetTime() an aliased GetTickCount() API?
No .
Re: Need help re-coding small function, and "Error trapping"
The Sleep API will actually halt processing. Is this what you are after?
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