Once my program starts, how would I get it to grab the time and have its own clock. I can do this however only be refreshing the label1.caption every second. There has to be a better method, any ideas?
Printable View
Once my program starts, how would I get it to grab the time and have its own clock. I can do this however only be refreshing the label1.caption every second. There has to be a better method, any ideas?
hi,
create a timer, set the interval to 1000 and make sure that it is enabled, then put the following code in it
label1.caption = time
hope this helps
Merlin ?
zmerlinz has told you how most of us would probably do the job. Having a timer set to 1000 milliseconds is not much of a burden on the system if that is what you are worried about.
When he mentioned "put the following code in it", of course, he means ion the Timer1_Timer event.
Regards
Paul Lewis
If you just want a clock. Add a status bar control and set one the panel to be a clock.
:):)
The most you can update the standard clock is by 1 second. You would just be repeating many times if you went lower.Quote:
Originally posted by PaulLewis
How frequently do you want to update?
As timer control is a very inaccurate timer (up to 53 ms), you may notice it won't update each second if you put interval to 1000ms. you may have to update it each 100 ms if you want to have a accurate looking clock or you would have to use a loop with a timer method or use settimer api
I don't think API is necessary for making a simple clock on the program. If you want it really accurate, just set the Timer's interval to 1.
Long time ago when I still used timers to make clocks I setted it's interval to 200 or 300 so it nearly updates every second. To prevent flickering check if the label already contains the time:
Code:Private Sub Timer1_Timer()
If Not Label1.Caption = Time Then: Label1.Caption = Time
End Sub
' only refresh label when time has changed
' timer at intervals of whatever 100ms?
timer1_timer()
localtimer = format(datetime,"h:mm:ss")
if localtimer <> lasttimer then
label1.caption = localtimer
lasttimer = localtimer
end if
exit sub
Just by setting it to 1 you won't get it accurate less than 53 millisecond and the event will also fire less than 20 times a secondQuote:
If you want it really accurate, just set the Timer's interval to 1.
That is a good thing, kedaman, because we are only concered with the accuracy of the second, not the milliseconds.
If there's a visual purpose, you want to have the time to be updated using an event which won't be accurate if you use timer control, therefore by setting a small interval you will update it as accurate as possible.
Yes, but that's what we want, as long as there is no flickering involved.
Clash of the Titans (GURU's) :)
What's this about the staus bar being set to clock? I've never heard of that!! Thanks's Glen. Think it's time to have a play...
Paul
Try something like this.
Code:Private Sub Timer1_Timer()
StatusBar1.Panels(1).Text = Time
End Sub
Unless you require a clock with seconds you don't need to use a timer with the status bar. Just set the style property of the panel to sbrTime.
:):)