Here is the code of this public sub:
Public Sub Pause(NbSec As Single)
Dim Finish As Single
Finish = Timer + NbSec
DoEvents
Do Until Timer >= Finish
Loop
End Sub
First of all, this Public Sub is used in order to put an interval between actions. It can be used in many situation. To use it, you need to type "pause" and "1" (for a pause of 1 second, 0.2 for a 1/5 second pause...) Let see some exemple of application:
Open a new project and add the Public Sub Pause to your code page. Then, in general section, declare the following variables:
Dim x1 As Long, x2 As Long, y1 As Long, y2 As Long, time As Byte
Now in: Form_Click paste the following code:
For time = 1 To 200
Randomize
x1 = Int(Rnd * 5000)
y1 = Int(Rnd * 3000)
x2 = Int(Rnd * 5000)
y2 = Int(Rnd * 3000)
Me.DrawWidth = 1
Me.Line (x1, y1)-(x2, y2), QBColor(5)
Next time
Test it and notice the speed of the line draw. Now add
Pause 0.1 after
Me.Line (x1, y1)-(x2, y2), QBColor(5)
Test it again. You see the line are drawn slower. For and Next are one of the Pause Sub application but you can use is everywhere you want an pause between to events.
What you have learned:
- What is the Public Sub Pause
- How to use the Public Sub Pause
This article was originally written by Welk |