Date and Time in VB6 Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mohan Krishna
    New Member
    • Oct 2007
    • 115

    Date and Time in VB6 Form

    Hi everyone

    I use the following code in VB 6 Form (Timer function) to show the date and time in textboxes.
    My question is when the form is loaded, the textbox doesn't show the time immediately but takes some delay.

    Why so? How can we reduce that delay?

    Code:
        'txtLoginDt = Date
        txtLoginDt = Format(Date, "ddd, mmm dd, yyyy")
        'txtLoginTm = Time
        txtLoginTm = Format(Time, "hh:mm:ss Am/PM")
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #2
    Originally posted by Mohan Krishna
    Hi everyone

    I use the following code in VB 6 Form (Timer function) to show the date and time in textboxes.
    My question is when the form is loaded, the textbox doesn't show the time immediately but takes some delay.

    Why so? How can we reduce that delay?

    [CODE=vb]
    'txtLoginDt = Date
    txtLoginDt = Format(Date, "ddd, mmm dd, yyyy")
    'txtLoginTm = Time
    txtLoginTm = Format(Time, "hh:mm:ss Am/PM")
    [/CODE]
    Can explain us in more details. Did you used 2 different timer for the time and date? Their intervals? Does interval is set to 1000?

    Comment

    • Mohan Krishna
      New Member
      • Oct 2007
      • 115

      #3
      Originally posted by lotus18
      Can explain us in more details. Did you used 2 different timer for the time and date? Their intervals? Does interval is set to 1000?
      Hi,
      Thanks for response!
      Yes, I am using one timer and the interval is set to 1000.

      Comment

      • keign
        New Member
        • Nov 2007
        • 8

        #4
        No delay for me, I've tried it.
        Last edited by Killer42; Nov 20 '07, 11:03 PM.

        Comment

        • lotus18
          Contributor
          • Nov 2007
          • 865

          #5
          Originally posted by Mohan Krishna
          Hi,
          Thanks for response!
          Yes, I am using one timer and the interval is set to 1000.
          I'm not sure by this. Try to set your interval to 1.

          Hope it helps

          Comment

          • AHMEDYO
            New Member
            • Nov 2007
            • 112

            #6
            HI...

            thats must be, because the interval must expired then timer code will be executed, you can call timer sub 1 time in your form load

            for example

            [CODE=vb] Call Timer1_Timer()[/CODE]

            GOOD LUCK

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by lotus18
              ...Try to set your interval to 1.
              I like AHMEDYO's response. But I wouldn't recommend setting the timer interval to 1. You will be trying to update the date and time 1000 times per second. This is likely to slow down other operations.

              Comment

              • Mohan Krishna
                New Member
                • Oct 2007
                • 115

                #8
                Thank You AHMEDYO and KILLER42 !

                It worked by calling the timer function in form load.

                ThanQ!

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  Originally posted by Mohan Krishna
                  Thank You AHMEDYO and KILLER42 !

                  It worked by calling the timer function in form load.
                  Excellent! Glad to hear you've got it sorted.

                  (Note, lotus18's suggestion was quite valid, too. Although I pointed out a potential problem, it can be easily prevented.)

                  Comment

                  Working...