Thread: VBA Timer
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
moon[_5_] moon[_5_] is offline
external usenet poster
 
Posts: 40
Default VBA Timer

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





"Lisa" schreef in bericht
...
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


"moon" wrote in message
. ..

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




"Lisa" schreef in bericht
...
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