Results 1 to 5 of 5

Thread: [RESOLVED] Simple way to add the current date and time to a form?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Location
    England
    Posts
    24

    Resolved [RESOLVED] Simple way to add the current date and time to a form?

    Hey, I was just wondering if anyone could help me in adding basically just the current date and time to a textbox/label or something like that? I have looked at coding but everyone seems to do it in such a complex way. Is there not a simple way of doing this? I don't want to use the date time picker as I don't want a user to be able to select the date or time.

    Thanks.

  2. #2
    Addicted Member
    Join Date
    Jun 2009
    Posts
    245

    Re: Simple way to add the current date and time to a form?

    You could use DateAndTime.Now

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Location
    England
    Posts
    24

    Re: Simple way to add the current date and time to a form?

    Erm ok, but how would I go about adding that? I am new to VB, hence why I am asking what is probably a stupid question to many people.

  4. #4
    Addicted Member
    Join Date
    Jun 2009
    Posts
    245

    Re: Simple way to add the current date and time to a form?

    Ah, no problem

    Firstly, add a label to your form. If it's your first label in your program, it will be automatically be named 'label1'. Now, if you want to refresh your label, so it displays the current date/time, you'll need a timer. So, just add a timer and set it's interval property to 1000 and enabled to true. You'll find these properties in the properties-windows in the design view.

    Now, it's time to add some code. Double click on your timer that you added, and the code window will pop up with the timers tickevent-sub automatically created for you. Everything you put inside this sub, will be executed every time the timer tick event occures, witch is every 1000 millisecond in this case.

    So to display time/date in the label you created, add this line in your timer-sub:

    Code:
    Label1.Text = DateAndTime.Now
    Feel free to ask if I was unclear at some point

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Location
    England
    Posts
    24

    Re: Simple way to add the current date and time to a form?

    Thanks very much, that was very helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width