ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   time (https://www.excelbanter.com/excel-programming/376110-time.html)

Zaahir

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

Ozgur Pars[_2_]

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


Ozgur Pars[_2_]

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


Zaahir

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


Ozgur Pars[_2_]

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


Zaahir

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



All times are GMT +1. The time now is 12:54 PM.

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