#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Stop timer.

Hi All,

I copied a script from discussions given below to prepare a rudementary clock.

Sub Clock()
ThisWorkbook.Sheets("Sheet1").Range("g7").Value = CDbl(Time)
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "Clock"
End Sub

I would like to have a seperate macro to stop this clock from calculating.

Thanks for your help in advance.....!

--
Karthi
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Stop timer.

Hi Karthi,

Note that NextTick need to be declared in the declarations area at the top
of the module so that it is available to all subs in the module.

Dim NextTick

Sub StopClock()
'Stop OnTime event.
'Returns error if clock already stopped and hense the On Error handling.
On Error Resume Next
Application.OnTime _
EarliestTime:=NextTick, _
Procedu="Clock", _
Schedule:=False
If Err.Number 0 Then Exit Sub
On Error GoTo 0
End Sub

--
Regards,

OssieMac


"Karthik" wrote:

Hi All,

I copied a script from discussions given below to prepare a rudementary clock.

Sub Clock()
ThisWorkbook.Sheets("Sheet1").Range("g7").Value = CDbl(Time)
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "Clock"
End Sub

I would like to have a seperate macro to stop this clock from calculating.

Thanks for your help in advance.....!

--
Karthi

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Stop timer.

Also CDbl(Time) appears to be a UDF (User Defined Function). You could simply
use the following in lieu. (Set the fomat between the double quotes to
whatever format you want.)

The space and underscore at the end of the line is a line break in an
otherwise single line of code.

ThisWorkbook.Sheets("Sheet1").Range("g7").Value _
= Format(Now(), "hh:mm:ss")


--
Regards,

OssieMac


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Stop timer.

Hello yet again Karthi,

Your question prompted me to write some code that more fully covers timers.
It records the start time in cell A1, then the progressive time is displayed
in cell A2 and after the timer is stopped the total elapsed time is displayed
in cell A3.

Unlike the times entered as text with the format function as per my previous
post, these times can be added and subtracted etc (used in maths equations
etc).

You start the timer from Sub StartTiming()

Dim NextTick 'Must be declared in the declarations section before any subs.

Sub StartTiming()

Call StartClock

With ThisWorkbook.Sheets("Sheet1")
'Clear total elapsed time
.Range("A3").ClearContents

'Format the cells with time formats
.Range("A1:A3").NumberFormat = "hh:mm:ss"

'Save the start time in cell A1
.Range("A1").Value = Range("A2").Value

End With

End Sub

Sub StartClock()

With ThisWorkbook.Sheets("Sheet1")
.Range("A2") = Now()
End With

NextTick = Now + TimeValue("00:00:01")

Application.OnTime NextTick, "StartClock"
End Sub

Sub StopClock()
'Stop OnTime event.
'Returns error if already stopped and hense the on error handling.
On Error Resume Next

Application.OnTime _
EarliestTime:=NextTick, _
Procedu="StartClock", _
Schedule:=False

If Err.Number 0 Then Exit Sub

On Error GoTo 0
With ThisWorkbook.Sheets("Sheet1")
.Range("A3").Value _
= .Range("A2").Value - .Range("A1").Value
End With

End Sub

--
Regards,

OssieMac


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Stop timer.

Chip Pearson explains application.ontime at:
http://www.cpearson.com/excel/OnTime.aspx

Karthik wrote:

Hi All,

I copied a script from discussions given below to prepare a rudementary clock.

Sub Clock()
ThisWorkbook.Sheets("Sheet1").Range("g7").Value = CDbl(Time)
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "Clock"
End Sub

I would like to have a seperate macro to stop this clock from calculating.

Thanks for your help in advance.....!

--
Karthi


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Stop timer.

Hi Karthi

For a simple solution, do a test for something before Application.ontime.
Here you stop it by putting anything in the neighbor cell:

If ThisWorkbook.Sheets("Sheet1").Range("h7").Value < "" Then Exit Sub
Application.OnTime Nexttick, "Clock"

A boolean public variable is probably a better choice.

HTH. Best wishes Harald


"Karthik" skrev i melding
...
Hi All,

I copied a script from discussions given below to prepare a rudementary
clock.

Sub Clock()
ThisWorkbook.Sheets("Sheet1").Range("g7").Value = CDbl(Time)
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "Clock"
End Sub

I would like to have a seperate macro to stop this clock from calculating.

Thanks for your help in advance.....!

--
Karthi



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Stop timer.


Thank you so much for this piece of code. I am also looking for
something exactly like this. My problem is that the stop clock macro
didn't work. Any suggestions? I tried adding a button to trigger the
macro and just running the macro through the excel menu bar, and neither
worked.


OssieMac;598379 Wrote:

Hello yet again Karthi,

Your question prompted me to write some code that more fully covers

timers.
It records the start time in cell A1, then the progressive time is

displayed
in cell A2 and after the timer is stopped the total elapsed time is

displayed
in cell A3.

Unlike the times entered as text with the format function as per my

previous
post, these times can be added and subtracted etc (used in maths

equations
etc).

You start the timer from Sub StartTiming()

Dim NextTick 'Must be declared in the declarations section before any

subs.

Sub StartTiming()

Call StartClock

With ThisWorkbook.Sheets("Sheet1")
'Clear total elapsed time
.Range("A3").ClearContents

'Format the cells with time formats
.Range("A1:A3").NumberFormat = "hh:mm:ss"

'Save the start time in cell A1
.Range("A1").Value = Range("A2").Value

End With

End Sub

Sub StartClock()

With ThisWorkbook.Sheets("Sheet1")
.Range("A2") = Now()
End With

NextTick = Now + TimeValue("00:00:01")

Application.OnTime NextTick, "StartClock"
End Sub

Sub StopClock()
'Stop OnTime event.
'Returns error if already stopped and hense the on error handling.
On Error Resume Next

Application.OnTime _
EarliestTime:=NextTick, _
Procedu="StartClock", _
Schedule:=False

If Err.Number 0 Then Exit Sub

On Error GoTo 0
With ThisWorkbook.Sheets("Sheet1")
.Range("A3").Value _
= .Range("A2").Value - .Range("A1").Value
End With

End Sub

--
Regards,

OssieMac



--
apandbp
------------------------------------------------------------------------
apandbp's Profile: http://www.thecodecage.com/forumz/member.php?u=550
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=165832

http://www.thecodecage.com/forumz


--- news://freenews.netfront.net/ - complaints: ---
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Stop timer.


apandbp;740473 Wrote:

Thank you so much for this piece of code. I am also looking for
something exactly like this. My problem is that the stop clock macro
didn't work. Any suggestions? I tried adding a button to trigger the
macro and just running the macro through the excel menu bar, and neither
worked.

Maybe you need to re-read the thread, there is a stop timer macro there
and it works as it should.


--
Simon Lloyd

Regards,
Simon Lloyd
'Microsoft Office Help' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?u=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=165832

http://www.thecodecage.com/forumz


--- news://freenews.netfront.net/ - complaints: ---
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Timer w/ Start, Stop, Pause dgold82 Excel Programming 2 April 22nd 09 10:13 PM
How to stop 'Egg Timer' MichaelRobert Excel Programming 3 December 4th 08 09:43 PM
Stopping a Timer / Running a timer simultaneously on Excel Paul23 Excel Discussion (Misc queries) 1 March 10th 06 12:08 PM
How do I stop other circles in other cells to stop selecting? stauff Excel Worksheet Functions 2 October 29th 04 09:02 PM
stop timer choice[_2_] Excel Programming 1 October 25th 04 12:29 AM


All times are GMT +1. The time now is 06:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"