Show date and time on form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • variouz3ckz
    New Member
    • Jul 2007
    • 18

    Show date and time on form

    Guys, will some send me some hints on how to display a time and date in my form... the basic one because im just starting to learn VB!
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by variouz3ckz
    Guys, will some send me some hints on how to display a time and date in my form... the basic one because im just starting to learn VB!
    Can you just give us a few more details? Like, do you just want to put the date and time once in a text box, or print it onto the form? Or do you want it in a "status bar" type thing at the bottom, constantly updated, or what? (It's not as hard as it sounds - there's a control which provides this more or less automatically).

    And what version of VB are you using?

    Comment

    • variouz3ckz
      New Member
      • Jul 2007
      • 18

      #3
      Originally posted by Killer42
      Can you just give us a few more details? Like, do you just want to put the date and time once in a text box, or print it onto the form? Or do you want it in a "status bar" type thing at the bottom, constantly updated, or what? (It's not as hard as it sounds - there's a control which provides this more or less automatically).

      And what version of VB are you using?
      ei Killer42, thanks for the response, i am using a VB6 version i need to display it in a text box, or maybe its kind of you to show me the codes in "status bar" thing type... well is it hard to study vb6?! well give me some advice and guidelines to understand it gradually... hoping for ASAP response...

      Comment

      • fplesco
        New Member
        • Jul 2007
        • 82

        #4
        Hi variouz3ckz -

        When you use textbox, try this

        for date:
        <OBJECT NAME>.text = format(now,"mm/dd/yyyy")
        example: txtDate.text = format(now,"mm/dd/yyyy")

        for time which will dynamically change every second.
        Step 1. Put Timer object into your form.
        Step 2. Set its "Interval" property to 1000.
        Step 3. Double-click on the Timer control.
        Note: There must be function created for Private Sub Timer_.... and End Sub

        Step 4. Between Private Sub and End Sub, put this code below
        txtTimer.text = format(now,"mm: hh:ss AM/PM")

        txtTimer must be the name of the textbox you want the time to put into.

        If you want to use the Status Bar object, much easier, just add panels and set panel "Style" property to 5 - sbrTime or 6 - sbrDate.

        Hint: Select status bar object, in the Properties window click on "(Custom)" and the "Property Pages" form will pop up. Click on "Panels" tab and you will find the "Style" dropdown box.

        Hope this would help you.

        Have a nice day!

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Note, to use the StatusBar control you have to go to "Project | Components" and select "Microsoft Windows Common Controls" (the version number will probably be 5 or 6). This will add the StatusBar control (as well as a few others) to your toolbox.

          Comment

          • variouz3ckz
            New Member
            • Jul 2007
            • 18

            #6
            Originally posted by fplesco
            Hi variouz3ckz -

            When you use textbox, try this

            for date:
            <OBJECT NAME>.text = format(now,"mm/dd/yyyy")
            example: txtDate.text = format(now,"mm/dd/yyyy")

            for time which will dynamically change every second.
            Step 1. Put Timer object into your form.
            Step 2. Set its "Interval" property to 1000.
            Step 3. Double-click on the Timer control.
            Note: There must be function created for Private Sub Timer_.... and End Sub

            Step 4. Between Private Sub and End Sub, put this code below
            txtTimer.text = format(now,"mm: hh:ss AM/PM")

            txtTimer must be the name of the textbox you want the time to put into.

            If you want to use the Status Bar object, much easier, just add panels and set panel "Style" property to 5 - sbrTime or 6 - sbrDate.

            Hint: Select status bar object, in the Properties window click on "(Custom)" and the "Property Pages" form will pop up. Click on "Panels" tab and you will find the "Style" dropdown box.

            Hope this would help you.

            Have a nice day!
            ei fplesco... the information you gave me was good.. but the time and date doesnt automatically appear in the form as i play it. i need to press any key, to make the appearance in the textbox.

            tnx for helpin'
            have a nice day...

            Comment

            • cloud24
              New Member
              • Jan 2012
              • 1

              #7
              Originally posted by variouz3ckz
              ei fplesco... the information you gave me was good.. but the time and date doesnt automatically appear in the form as i play it. i need to press any key, to make the appearance in the textbox.

              tnx for helpin'
              have a nice day...
              try putting the code given to you under Private Sub Form_Load()

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Thanks cloud24, that's good advice.

                It may, however, be a little late for variouz3ckz, since his/her question was posted about 4½ years ago. :)

                Comment

                Working...