Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Date and Time (http://www.programmingforums.org/showthread.php?t=13278)

Robocop Jun 4th, 2007 12:03 PM

Date and Time
 
I want to be able to put a continuing date and time text on an application.

I can use this fuction: Format(Now, "f"), which outputs: Monday, June 04, 2007 12:12PM ,but once the date and time is shown, it will stay the same forever...

I guess It would need to work with a timer or something, but can somebody please give me some help on this?

Thanks in advance!

Booooze Jun 4th, 2007 1:09 PM

Just throw it in a timer_tick event. Set its enabled property to true, and have it update every second.

teishu Jun 4th, 2007 3:10 PM

yeh as Booze said.. add a timer to you application. set its event to whatever the code is to update your clock.. and enable it to update every 100 (thats in millisecs)

mattireland Jul 6th, 2007 5:23 PM

Yeh 100 milliseconds should be OK for you! Are you OK with the exact syntax? What you wrote looked good.

john Wesley Jul 6th, 2007 5:54 PM

I have not done anything in VB.NET for a while but does an Timer object not need to be started explicitly rather than simply enabled? - Im sure it does, so enabling an instance in your application will be a little disappointing.

Ben.Dougall Jul 6th, 2007 10:49 PM

1 Attachment(s)
Very simple example to show what i think you want. Make a form, with a label, and two buttons, IF you click the first button starts the timer ( <timername>.start() ), second button ( <timername.stop> ). The rest you should be able to get from the code below.

:

  1. Public Class Form1
  2.  
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         Timer1.Start()
  5.     End Sub
  6.  
  7.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  8.         Timer1.Stop()
  9.  
  10.     End Sub
  11.  
  12.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  13.         Label1.Text = DateTime.Now()
  14.     End Sub
  15. End Class



The attached is a all the files from my little test project, made in VS2005 SP1.

mattireland Jul 7th, 2007 3:57 AM

Yep but make sure you drag it from the toolbox first!


All times are GMT -5. The time now is 11:25 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC