Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

pleg12345 (IS/IT--Management) (OP)
12 Apr 04 8:34
Please can somebody help me?

I need to build a time counter in short-time with a button to stop and start the time.

The time counter would count up from 00:00 up to say 99:59?

Please can someone advise?
DeanWilliams (Programmer)
13 Apr 04 5:29
Hi,

Try this:

(I will put the names I have used in brackets).

Create a label on the form (lblDisplay). Create a Start/Stop command button (cmdStopStart), and (maybe) a reset command button (cmdReset).

Then add the following code to your form:

CODE


Dim datCurrent As Date
Dim blnCount As Boolean

Private Sub cmdReset_Click()
    datCurrent = #00:00#
    lblDisplay.Caption = Format(datCurrent, "Short Time")
End Sub

Private Sub cmdStopStart_Click()
    If Not blnCount Then
        cmdStopStart.Caption = "Stop"
    Else
        cmdStopStart.Caption = "Start"
    End If
    blnCount = Not blnCount
End Sub

Private Sub Form_Timer()
    If blnCount Then
        datCurrent = DateAdd("n", 1, datCurrent)
        lblDisplay.Caption = Format(datCurrent, "Short Time")
    End If
End Sub

Set the Timer Interval on the Forms property sheet on the events tab to 60000, so it will fire once every 60 secs.

For added effect you could set the label controls properties (on property sheet) to make it look like a real clock:

Caption - 00:00
Fore Color - 65280
Back Color - 0
Text Align - Center
Special Effect - Sunken

Hope I haven't forgotten anything.
Good luck,

Dean
pleg12345 (IS/IT--Management) (OP)
13 Apr 04 11:24
cheers for the code Dean, but there is a problem!

The Timer does not start for some reason?

Can you help?
DeanWilliams (Programmer)
14 Apr 04 4:28
In the OnTimer event, do you have [Event Procedure] selected in the property sheet for the form.

pleg12345 (IS/IT--Management) (OP)
14 Apr 04 11:18
Yeah i do?

why?

any help?
DeanWilliams (Programmer)
15 Apr 04 6:58
I just forgot to explicitly mention setting that in my original post and thought you may not have...

Anyway, is it still not working then? You definitely have the Timer Interval Set to 60000?


Actually, when I tested this I included seconds which made it more obvious that the timer was running. You said you wanted the time in a Short-Time format. So the above set up only counts minutes. Maybe you wanted seconds and minutes?

If so, make the following changes to these functions:

CODE

Private Sub cmdReset_Click()
    datCurrent = #00:00:00#
    lblDisplay.Caption = Format(datCurrent, "Long Time")
End Sub

Private Sub Form_Timer()
    If blnCount Then
        datCurrent = DateAdd("s", 1, datCurrent)
        lblDisplay.Caption = Format(datCurrent, "Long Time")
    End If
End Sub
Also Change the Timer Interval to 1000 and the original caption of the display label to "00:00:00".

Maybe that's what you wanted - I thought it was a bit strange you didn't want seconds on it.

Dean.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close