![]() |
Visual Basic Current Time On Form
How do I show the current time on the form in a label, and update it every second or maybe every minute???
I put "lblTime.Text = DateTime.Now" into a OnClick sub, but that only works when I click it... how do I get it to change every few seconds, or minute????? also How can I at the same time on another label make a timer that counts up continuously from when the application loads? thanks -S_E |
Re: Visual Basic Current Time On Form
:
lblTime.Text = DateTime.Now.Minute.ToString()Your best bet is use a timer to tick every minute and run that little bit of code. |
Re: Visual Basic Current Time On Form
ok, I guess I forgot to mention this. I'm a VB newbie.
This would be done how? |
Re: Visual Basic Current Time On Form
There is a timer object you can add to the form, it should be a little stop watch-like looking icon on the tools side bar. After adding it, set the interval to the number of miliseconds you want the timer to iterate itself (in this case, 1000 for one second, or 60000 for a minute).
The code you want executed goes inside of the timer itself. |
Re: Visual Basic Current Time On Form
I made a computer calander for someone not long ago, I think you may find the code helpful for what you're looking for , here is the entire code from the 1 I made
How to set or fill out the Properties: Form Name Calendar: Caption = My Computer Calendar BorderStyle = 1 - Fixed Single Timer1 Timer1: Interval = 1000 Label1 Name Day: BackStyle = 0 - Transparent Caption = Sunday FontName = Times New Roman FontBold = True FontSize = 24 Label2 Name Time: BackStyle = 0 - Transparent Caption = 00:00:00 PM FontName = Times New Roman FontBold = True FontSize = 24 Label3 Name Year: BackStyle = 0 - Transparent Alignment = 2 - Center Caption = 2008 FontName = Times New Roman FontBold = True FontSize = 24 Label4 Number: BackStyle = 0 - Transparent Alignment = 2 - Center Caption = 30 FontName = Arial FontBold = True FontSize = 72 Label5 Month: BackStyle = 0 - Transparent Alignment = 2 - Center Caption = March FontName = Times New Roman FontBold = True FontSize = 24 Now for the Code: General Declarations: timDisplay Timer Event: Private Sub Timer1_Timer() Dim Today As Variant Today = Now Day.Caption = Format(Today, "dddd") Month.Caption = Format(Today, "mmmm") Year.Caption = Format(Today, "yyyy") Number.Caption = Format(Today, "d") Time.Caption = Format(Today, "h:mm:ss ampm") End Sub |
| All times are GMT -5. The time now is 3:39 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC