|
-
May 21st, 2007, 09:41 PM
#1
Thread Starter
Addicted Member
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?)
-
May 21st, 2007, 09:51 PM
#2
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
-
May 21st, 2007, 10:20 PM
#3
Thread Starter
Addicted Member
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
-
May 21st, 2007, 11:15 PM
#4
Re: Need help re-coding small function, and "Error trapping"
 Originally Posted by leinad31
Is timeGetTime() an aliased GetTickCount() API?
No .
-
May 22nd, 2007, 07:11 AM
#5
Re: Need help re-coding small function, and "Error trapping"
The Sleep API will actually halt processing. Is this what you are after?
-
May 22nd, 2007, 08:04 AM
#6
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|