Counting one second

  • Thread starter Thread starter Steven
  • Start date Start date
S

Steven

I am using the following but I do not like it because it
is not consistent.

Dim Timer as Double
Timer = Second(Time)
Do Until Timer = Second(Time) + 1
Loop

This is not consistent because it may not count a full
second depending on how close the second was to the next
second when you assigned the value to Timer.

How do you time an actual one second of time?

Thank you.

Steven
 
Try using the Millisecond timer built in to Windows.

First make this declare in a module outside of a sub or function

Public Declare Function GetTime Lib "winmm.dll" Alias "timeGetTime" () As
Long

Then you can use it like this

Public Sub WaitSecond(intSecondsToWait)
Dim lngEnd As Long

lngEnd = GetTime + CLng(intSecondsToWait * 1000)

While GetTime < lngEnd
DoEvents
Wend
Debug.Print "Done waiting ";intSecondsToWait;" Seconds"
End Sub

Even though this is suppose to be accurate to the millisecond. I have found
that the best you can realistically hope for is from around 20 to 50 Ms.
depending on what else is going on with your computer at the time. Please
do not use this to regulate nuculear reactors or chemical plants.

Ron W
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top