VB Noob and the Date

  • 12 years ago

    I can not figure out how to dispaly todays date on a VB Form.

     

    I am currently trying to have a label in the upper right corner so that it displays the current date.  I have searched and can only find Textbox codes that don't work.

  • 12 years ago
    Label.Caption=date
  • 12 years ago

     Didn't work.  Here are teh things I've tried so far.

     

    Private Sub Today()
            Dim Today As Date
            Today = DateAndTime.Now

            lblDate.Text = Today
        End Sub


        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            lblDate.Text = Now
        End Sub

  • 12 years ago
    Lbldate.Caption=now are you using vb.Net. I thought vb 6. I don't know vb.Net. What response are you getting while using your code...?
  • 12 years ago

     If u r using vb.net , this code will help u,

     

     lblDate.Text=System.DateTime.Today

    or

     

      lblDate.Text=System.DateTime.Now (this show the time also)

  • 12 years ago

     I am using VB 2008

     

    I get no errors, but I don't get any date output either.

     

    When I copy and paste lblDate.Text=System.DateTime.Now it says (Declaration Expected)

  • 12 years ago

    in all other versions of vb from vb3 to vba in 2007, NOW is a function that returns a date string that must be formatted to express the date and time as the user wishes..

     is this not the case with your basic... i.e.

    something takes the return value of the function NOW

    S=now()

    the brackets matter as you are calling a function even though it requires no parameters they simply signal the functioness rather than subroutiness of the token NOW

    normally you need to specify what the returned date-time thing should look like...

    e.g S=format(now(),"dd/mm/yy hh:mm:ss")

    or some such

    hope this helps

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint Exupéry