
Originally Posted by
JoshHilton
Try using this.
Sub Pause(Duration)
starttime = Timer
Do While Timer - starttime < Duration
DoEvents
Loop
End Sub
Pause(5)
Your code is a CPU hog. I know because I used to use it. However, the code below uses the same concept but employs the Sleep API with 1mS Sleep calls. This is a very versatile procedure because you can put a Pause call nearly anywhere. It's great for debugging too! Pause 3 = 3 Seconds.
Code:
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' Credits: (Milk (Sleep+Pause Sub)). (Wayne Spangler (Pause Sub))
Private Sub Pause(ByVal Delay As Single)
Delay = Timer + Delay
If Delay > 86400 Then 'more than number of seconds in a day
Delay = Delay - 86400
Do
DoEvents ' to process events.
Sleep 1 ' to not eat cpu
Loop Until Timer < 1
End If
Do
DoEvents ' to process events.
Sleep 1 ' to not eat cpu
Loop While Delay > Timer
End Sub
Private Sub Form_Load()
Me.Show
Dim i As Integer
For i = 1 To 10
Me.Caption = "Pausing " & i
Pause 1 ' Call Pause (1 second)
Next
Me.Caption = "Done"
End Sub