Actually, guys....it is FAR better to use the sleep api.
Today's modern computers can easily execute 40 million VBA instructions per
second. You read this right...40 million VBA instructions! We are not
talking about compiled c, or assembler, but good old fashioned VBA. These
new computers are blindly fast!
If you run a blank loop, or use the sleep api, you don't service the users
anyway.
However, by using the sleep api, you don't ask that processor to execute
those HUGE number of loops. Those loops are really like flooring the gas
pedal, takes all of the processing the cpu can give. While windows does a
great job of giving processing to all other tasks..you do run the pants off
of the processor when running a blank loop.
When you use the sleep api, then the time slice and ALL processing is given
to the rest of the windows system.
So, there NO difference in responsiveness when using either approach, but
running a processing loop to slow down, or cause a delay will also impact
all other processing on the computer. This is simply a waste of the
incredible and blindingly huge amount of processing we have at our finger
tips these days. Thus the api sleep should be used, as it will NOT use ANY
processing, but release all resources to OTHER windows programs.
The ONLY reason to use your own custom loop is that you CAN do some event
processing at the SAME TIME, or even check for user actions (like a cancel
button for a VERY long process)
for i = 1 to 100
' crunch some data sub
DoEvents
if forms!MyProGressBar.Cancelled = true
If MsgBox("Cancel this long update?", vbQuestion + vbYesNo) = vbYes
Then
exit for
end if
end if
next i
In the above, adding the doEvents means that all mouse clicks etc are
processed. If we use a sleep api, then you can't do that. However, we are
not talking about un-responsive problem with our code..but in fact just want
a delay.
If you just want the code to wait, then sleep the poor computer. There will
no difference in your programs responsiveness..but it will impact OTHER
programs running if you use tons of processing to just make your program
wait.
--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
(E-Mail Removed)
http://www.attcanada.net/~kallal.msn