From N V Fitton, ideas to share with my students at Northern Virginia Community College, Alexandria campus.
I teach mathematics and computer science.

Tuesday, April 04, 2006

130 making your program pause

So you can admire it while it does its thing... Cut and paste the following at form level, i.e., above the rest of the code in your form:


Private Declare Function GetTickCount _
Lib "kernel32" () As Long
' --- get a function from library
' --- returns milliseconds since last boot of system

Public Sub Pause(Milliseconds As Single)
' --- make this procedure available
' --- throughout this form

Dim TicksNow As Single
Dim TicksAtStart As Single

TicksAtStart = GetTickCount()
TicksNow = GetTickCount()

Do Until ((TicksNow - TicksAtStart) >= Milliseconds)
TicksNow = GetTickCount()

DoEvents()
' --- allows OS to handle other events while counting down
' --- keeps this procedure from locking up itself or others

Loop

End Sub


I did not invent this code, but I did revise what I found on the net to make it a little more readable.

0 Comments:

Post a Comment

<< Home