clock on user form

N

NDBC

I have set up a user form (userform1) and would like to show the time on the
form in the textbox named clock1 as soon as the form is opened and have it
stay up the whole time until the form is closed. This is what I have tried.
It doesn't seem to do anything.

Sub RClock1()
Clock1.Text = CDbl(Time)

' Set up the next event one second from now
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "RClock1"
End Sub

I have the code in the code section for userform1.

Any ideas. Thanks
 
J

Jacob Skaria

Insert a module and paste the below code..

Sub Main()
Load UserForm1
UserForm1.Show
End Sub


In Code section of Userform

Private Sub UserForm_Activate()
RClock1
End Sub


Sub RClock1()
UserForm1.Clock1.Text = Format(Now, "hh:mm:ss")
UserForm1.Repaint
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "RClock1"
End Sub

If this post helps click Yes
 
N

NDBC

Jacob,

I did what you said. It gets the time into the textbox (a lot more than I
could do) but it does not change. The time just stays at the time you start
the form it does not tick. Any more ideas.

Thanks
 
J

Jacob Skaria

Oops..

In the module paste the below code..

Sub Macro1()
Load UserForm1
UserForm1.Show
End Sub

Sub RClock1()
UserForm1.Clock1.Text = Format(Now, "hh:mm:ss")
UserForm1.Repaint
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "RClock1"
End Sub

In Code section of Userform..paste the below

Private Sub UserForm_Activate()
Call RClock1
End Sub

and run macro1 from MacroList


If this post helps click Yes
 
N

NDBC

Jacob,

Worked a treat but I did not tell you the full story as I thought the
changes required would be easy. Should have known. What I really want is the
time since the race started in the text box. This is equal to Now - start
time. The start time is stored in cell b6 in sheet "Timing Sheet". This is
what I thought would work

Sub RClock1()
Watch = Now - sheets("timing sheet").cell("b6")
UserForm1.Clock1.Text = Format(Watch, "hh:mm:ss")
UserForm1.Repaint
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "RClock1"
End Sub

I should have known it wouldn't be that easy. Yet again, please show me how
to fix it.

Thanks
 
N

NDBC

Got it to work.

Sub RClock1()
Start = Sheets("Timing Sheet").Range("b6")
Watch = Now - Start
UserForm1.RaceClock1.Text = Format(Watch, "hh:mm:ss")
UserForm1.Repaint
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "RClock1"
End Sub

Cracked it. Thank you.
 
J

Jacob Skaria

I am not sure how this will affect your other routines. This should work

Sub RClock1()
Watch = Now - Sheets("timing sheet").Range("b6")
UserForm1.Clock1.Text = Format(Watch, "hh:mm:ss")
Application.OnTime Now + TimeValue("00:00:01"), "RClock1"
End Sub

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Can't Stop the clock 2
Can't stop a clock 1
Elapsed times > 24hrs 12
Stop timer. 7
How do i stop a clock in excel 0
countdown clock 0
Please Help 2
Blinking Button 2

Top