[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Constantly Changing Label Captions

Posted on 2004-09-27
8
Medium Priority
?
246 Views
Last Modified: 2010-05-02
I have a lable that will tell the current time ("The current time is: 12:00:54 PM"), but it needs to change every second. Right now I am defining the caption at Form_Load, but I don't know where to define the caption so that the form automatically re-captions the label every second. Help?
0
Comment
Question by:RunBoris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 400 total points
ID: 12158118
Hi RunBoris,

Make a timer and put it on your form, and set its name. Then, inside the timer script, add this:

Private Sub YourTimerName_Timer()
   yourLabelName.Caption = "The current time is: " & Time
End Sub

Regards,
Zyloch
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 160 total points
ID: 12158136
In addition to Zyloch's instructions, you need to set an interval for your timer or it won't fire  (the default is 0 which disables the timer).  The interval property is measured in milliseconds so if you set it to 1000, the timer will fire once a second.  You may want to use a smaller interval however, because the timer event may not fire at exactly one second if the system is busy.  This can make the clock appear to hang slightly before it updates, giving the impression that your application is slow and dosen't peform well.  With that in mind, I recommend using 333 milliseconds.  That interval is still slow enough where you won't see any impact on your programs (or any other programs) performance or CPU usage.

~IM
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12158142
Ah, oops, forgot about that. Sorry!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12158228
Just in case you are not sure how to "Make a timer and put it on your form", the Timer control is in the Toolbox along with other standard controls such as the Label, TextBox and CommandButton.  It looks like a classic analog stopwatch and if you hover your mouse over it, a tooltip that says "Timer" will appear.  Just drag one onto your form (the size doesn't matter) and then double click on it.  This will produce the default Timer event that is executed every XXX milliseconds when the Enabled property of your timer control is set to True:

    Private Sub Timer1_Timer()
       
    End Sub

~IM
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12159154
>>if you set it to 1000


set to 500 instead of 1000
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12159609
Hi EDDYKT,

You didn't read my comments very carefully.  =)

I actually recommended using 333.    The "if you set it to 1000" you quoted, was just an example I used to explain how the interval property works.

~IM
0
 

Author Comment

by:RunBoris
ID: 12161572
That did work, but I have a nit-picky question. Points will still be awarded based on the previous responses (Most Zyloch, partially Idle_Mind for the interval intervention).

Is there any other way of doing this? I ask because if the program isn't started exactly on a second, you can see a noticable difference in the system time, and my program's time. Obviously it's only off by a few milliseconds, but those sort of thing get to me in a weird OCD way. (OCD, obsessive compulsive disorder.... I'm a perfectionist... Sorry...)
0
 

Author Comment

by:RunBoris
ID: 12161627
Hmmm.... I just did some experimenting with the timer intervals. I set it all the way down to 1, and the system clock was still not in sync with my program. So, I think any other means of updating my silly label would be in vain. Points are now awarded!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question