VBA Timer

  • Thread starter Thread starter Lisa
  • Start date Start date
L

Lisa

Hi All,

I'm looking for a simple timer routine that will show the time elapsed for
each cycle of a Do Until ...Loop instruction. (the loop can go on for many
millions of cycles)

I'm thinking of something like :-

Before the *Do Until* starts t0 = current time

For each cycle within the loop t1 = current time and
Cells(1,1,) = t1-t0

But how?

Many thanks

Lisa

BTW I'm using XL97
 
Private Sub YourSub()
Dim pTime, pStart, pEnd, tTime, lTime
'five seconds
pTime = 5
pStart = Timer
Do While Timer < pStart + pTime
DoEvents
lTime = (pStart + pTime) - Timer
'update label (or anything else)
timeLabel.Caption = Round(lTime, 0)
Loop
pEnd = Timer
tTime = pEnd - pStart
End Sub
 
Thanks Moon,
I appreciate your help but is there not a simpler way to achieve this?
I'm sure your code will work but I understand very little of it and , as a
newbie, I need to learn in small doses.

Is it not possible to do it as I originally set it out?
i.e. at start t0 = current time
during loop t1 = current time
during loop shove the difference between t0 & t1 into a cell on the
worksheet

As I said, I appreciate any help but I can't help feeling that there must be
a simpler way.

Best Reagrds
Lisa
 
I think you can't make it with only t0 and t1, you'll need t2 & t3 too...


Public Sub YourSub()
Dim t0, t1, t2, t3
'5 seconds
t0 = 5
t1 = Timer
Do While Timer < (t1 + t0)
DoEvents
t3 = (t1 + t0) - Timer
Sheets(1).Cells(1, 1).Value = Round(t3, 0)
Loop
End Sub
 

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

Similar Threads

sheet cycle macro 1
Why could a suspended thread leak? 6
VBA forms in excel 2
vba timer 2
Inconsistent Sort 2
value is changing at the end of Call Sub 2
ADO Minus/Intersect? 3
Help with VBA 3

Back
Top