Results 1 to 7 of 7

Thread: How to create a simple timer that starts when you run program?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    4

    How to create a simple timer that starts when you run program?

    I want to make a label that shows how long the program runs in seconds. Any ideas? I am still a beginner in VB6.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: How to create a simple timer that starts when you run program?

    Are you really using VB6?

    It is hard to come by legitimately anymore, and many have been fooled by aggressive marketing into thinking the freebie VB.Net Express is VB6. They are actually quite different things.

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: How to create a simple timer that starts when you run program?

    Add your label to your form. Add a timer control to your form. Set the Interval of it to 1000. Keep the Enabled Property set to True
    add this code (double clikc on the timer and you only have to enter the middle line:
    Code:
    Private Sub Timer1_Timer()
    Label1.Caption = Now
    End Sub
    You can play around with the FORMAT command if you don't like what that label caption looks like/displays.

    EDIT: Good point, dile.....you posted as I was typing.

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: How to create a simple timer that starts when you run program?

    AND, what I posted is not quite what you want, but I'll let you figure that out. Get the time the program starts (NOW) in the form load routine. Save that and then calculate the difference every second in the timer. Very easy...let's see if you can do that. (IF you are using VB6, that is.)

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    4

    Re: How to create a simple timer that starts when you run program?

    We use it in school

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    4

    Re: How to create a simple timer that starts when you run program?

    thanks and yes it is VB6

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: How to create a simple timer that starts when you run program?

    So, have you figured out how to do this yet?
    Use the DateDiff function when you compare the start time (NOW()) with the current time every second in the timer.

    I have your solution, but want to see if you can get it yourself.

    Do what I said above (except the line in the timer)---you will be replacing that with a different line using DateDiff. Also, set a global variable like "startTime" in the form_load so you can compare that every second with the CURRENT time in the timer.

Tags for this Thread

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