#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default time

hi

i want to make a clock using a label, but of i use the time & now values,
the result returned is the time at which the macro was run....
How do i get the a watch response out of the label, to give me hh:mm:ss
continuously?
Regards
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default time

Hi Zaahir,
I tried to do the same on my userform and was told that in order for the
label to get constantatly updated one has to call a procedure every second
here is the code I got from the internet...(it updates every 60 seconds so
if you want it to update every second change to 1 and change the format to
hh:mm:ss)

Regards,
Ozgur

Public RunWhen As Double
Public Const cRunIntervalSeconds = 60
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub


Sub The_Sub()
UserForm2.Label475.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label476.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label514.Caption = Format(Now, "dd mmm yy hh:mm")
Call StartTimer
End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=False
End Sub


"Zaahir" wrote:

hi

i want to make a clock using a label, but of i use the time & now values,
the result returned is the time at which the macro was run....
How do i get the a watch response out of the label, to give me hh:mm:ss
continuously?
Regards

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default time

I forgot to tell you that you must call the Stoptimer procedure before you
close the workbook or the timer won't stop & excel will open the workbook.

"Ozgur Pars" wrote:

Hi Zaahir,
I tried to do the same on my userform and was told that in order for the
label to get constantatly updated one has to call a procedure every second
here is the code I got from the internet...(it updates every 60 seconds so
if you want it to update every second change to 1 and change the format to
hh:mm:ss)

Regards,
Ozgur

Public RunWhen As Double
Public Const cRunIntervalSeconds = 60
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub


Sub The_Sub()
UserForm2.Label475.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label476.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label514.Caption = Format(Now, "dd mmm yy hh:mm")
Call StartTimer
End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=False
End Sub


"Zaahir" wrote:

hi

i want to make a clock using a label, but of i use the time & now values,
the result returned is the time at which the macro was run....
How do i get the a watch response out of the label, to give me hh:mm:ss
continuously?
Regards

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default time

Thanx Ozgur, but where do i put all these codes?

"Ozgur Pars" wrote:

Hi Zaahir,
I tried to do the same on my userform and was told that in order for the
label to get constantatly updated one has to call a procedure every second
here is the code I got from the internet...(it updates every 60 seconds so
if you want it to update every second change to 1 and change the format to
hh:mm:ss)

Regards,
Ozgur

Public RunWhen As Double
Public Const cRunIntervalSeconds = 60
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub


Sub The_Sub()
UserForm2.Label475.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label476.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label514.Caption = Format(Now, "dd mmm yy hh:mm")
Call StartTimer
End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=False
End Sub


"Zaahir" wrote:

hi

i want to make a clock using a label, but of i use the time & now values,
the result returned is the time at which the macro was run....
How do i get the a watch response out of the label, to give me hh:mm:ss
continuously?
Regards

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default time

Zaahir,
in a module you can copy the code below:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 1
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub

Sub The_Sub()
ActiveSheet.Shapes(1).Select
Selection.Characters.Text = Format(Now, "hh:mm:ss")
Call StartTimer
End Sub

Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=False
End Sub


And in the "this.workbook" :

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call StopTimer
End Sub


The label shows the time continuasly once you execute the The_Sub procedure...

Hope this helps,
Ozgur


"Zaahir" wrote:

Thanx Ozgur, but where do i put all these codes?

"Ozgur Pars" wrote:

Hi Zaahir,
I tried to do the same on my userform and was told that in order for the
label to get constantatly updated one has to call a procedure every second
here is the code I got from the internet...(it updates every 60 seconds so
if you want it to update every second change to 1 and change the format to
hh:mm:ss)

Regards,
Ozgur

Public RunWhen As Double
Public Const cRunIntervalSeconds = 60
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub


Sub The_Sub()
UserForm2.Label475.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label476.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label514.Caption = Format(Now, "dd mmm yy hh:mm")
Call StartTimer
End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=False
End Sub


"Zaahir" wrote:

hi

i want to make a clock using a label, but of i use the time & now values,
the result returned is the time at which the macro was run....
How do i get the a watch response out of the label, to give me hh:mm:ss
continuously?
Regards



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default time


thanx
a few changes here & there did wonders...
ciao
"Ozgur Pars" wrote:

Zaahir,
in a module you can copy the code below:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 1
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub

Sub The_Sub()
ActiveSheet.Shapes(1).Select
Selection.Characters.Text = Format(Now, "hh:mm:ss")
Call StartTimer
End Sub

Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=False
End Sub


And in the "this.workbook" :

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call StopTimer
End Sub


The label shows the time continuasly once you execute the The_Sub procedure...

Hope this helps,
Ozgur


"Zaahir" wrote:

Thanx Ozgur, but where do i put all these codes?

"Ozgur Pars" wrote:

Hi Zaahir,
I tried to do the same on my userform and was told that in order for the
label to get constantatly updated one has to call a procedure every second
here is the code I got from the internet...(it updates every 60 seconds so
if you want it to update every second change to 1 and change the format to
hh:mm:ss)

Regards,
Ozgur

Public RunWhen As Double
Public Const cRunIntervalSeconds = 60
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub


Sub The_Sub()
UserForm2.Label475.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label476.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label514.Caption = Format(Now, "dd mmm yy hh:mm")
Call StartTimer
End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=False
End Sub


"Zaahir" wrote:

hi

i want to make a clock using a label, but of i use the time & now values,
the result returned is the time at which the macro was run....
How do i get the a watch response out of the label, to give me hh:mm:ss
continuously?
Regards

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
Time calculations for Scheduled Time vs. Actual Time Worked The Caterer Excel Discussion (Misc queries) 1 November 29th 09 08:08 AM
straight time, time and a half, and double time Jeremy Excel Discussion (Misc queries) 3 September 23rd 08 09:03 PM
Calculate Ending time using Start Time and Elapsed Time Chief 711 Excel Worksheet Functions 5 May 13th 08 04:34 PM
Subtracting Dates to get total time work time excluding weekends Jon Ratzel[_2_] Excel Discussion (Misc queries) 2 January 31st 08 10:36 PM
Calculating days & time left from start date/time to end date/time marie Excel Worksheet Functions 7 December 7th 05 02:36 PM


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

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

About Us

"It's about Microsoft Excel"