ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Timer (https://www.excelbanter.com/excel-programming/369737-vba-timer.html)

Lisa[_12_]

VBA Timer
 
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



moon[_5_]

VBA Timer
 

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




Jean-Yves[_2_]

VBA Timer
 
Hello,
Go in VBA heflp, time timer , see example.
It's all there

Regrds
JY

"Lisa" wrote in message
...
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




Lisa[_12_]

VBA Timer
 
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






moon[_5_]

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









All times are GMT +1. The time now is 01:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com