-
Hi All.
I'm looking for the best way to slow down a loop.
Is using a timer the best way to go.
Seems like a lot of overhead. I have done non productive
equations to slow things down also not good as it will
very a lot depending on the speed of the processor the
app is run on.
Any help greatfully accepted.
-
this works best for me - Spd is like 7000
Code:
Private Sub pause()
Dim i As Long
For i = 1 To Spd
DoEvents
Next
End Sub
there is an example at:
http://pages.about.com/vbmakai/sv1.htm
-
Thanks Makai
Thanks Makai for the fast reply.
Used it seems to work fine.
Damien :-)
-
Code:
Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
Private Sub pause(milliseconds as long)
Dim i As Long
i=Gettickcount+milliseconds
Do while Gettickcount<i
DoEvents
loop
End Sub
This ones a bit more adcanced, you can put the exact amount of millisecond for it to pause :)
-
Thanks Kedaman
I looked up GetTickCount and found that it rolls over to
zero if the system has been running for 49.7 days(obviously
not running a MicroSoft OS). Still stranger things have
happened. The pause routine could go into an infinite loop
if it was running when a system rolled over.
May be worth testing if count has just rolled over.
Once again thankyou for the advice
Damien
Code:
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub pause(milliseconds As Long)
Dim i As Long
i = GetTickCount + milliseconds
Do While GetTickCount < i
If GetTickCount < 3000 Then Exit Do 'TickCount loops over to zero every 49.7 days
DoEvents
Loop
End Sub
[Edited by Damien on 10-16-2000 at 11:58 PM]
-
how about 29247 years!
Yeah, not only if you have running your system for that long, but also you can pause like some years if you want, hehehe
Code:
Private Declare Function GetTickCount Lib "kernel32" () As Long
Sub pause(milliseconds As Currency)
Dim i As Currency, j As Currency, k As Currency
j = GetTickCount
i = j + milliseconds
Do While (j + k) < i
If GetTickCount < j Then k = k + j
j = GetTickCount
DoEvents
Loop
End Sub