Solved

How to make hour/minutes/second counter

Posted on 2006-11-18
5
353 Views
Last Modified: 2007-01-10
Hi experts,
I'm developing a simple application using VB and one of the output to display is total minutes starting from the application is open until it is close.

So i'm wondering how to make a counter that will count the minutes from the 1st minute until the last minutes which is when the application is close

Pls help

Thanks
0
Comment
Question by:mr_avril
5 Comments
 
LVL 29

Expert Comment

by:Nightman
ID: 17971446
use a Timer. You can set the interval every second (1000) if you want a 'seconds' part of your timer, and then simply increment the value that you are displayiing by 1 with every tick. If the value reaches 60, set to 00 and increment the minutes portion. If the minutes portion also reaches 60, increment the hours portion.

You can also set the timer interval to 60000 (60 seconds) if you only want it to count every minute.
0
 

Author Comment

by:mr_avril
ID: 17971460
Nvm.. I got it already :)

If i got another prob.. i find u guys again :)
anyway thanks
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 17971663
Here is the simplest way to do an "up" counter:

Option Explicit

Private startDate As Date

Private Sub Form_Load()
    startDate = Now
    Timer1.Interval = 1000
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Dim elapsed As Date
    elapsed = Now - startDate
    Label1.Caption = Format(elapsed, "hh:mm:ss")
End Sub
0
 
LVL 15

Expert Comment

by:cquinn
ID: 17978311
If the user clicks away from the form, the clock may stop if using the timer object, giving you incorrect times

Have a look at this post - use GetTickCount when the program loads, and then refer to the current value of GetTickCount with the timer - if the clock is stopped by the loss of focus, it will catch up again when it regains focus

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21974033.html
0
 
LVL 29

Expert Comment

by:Nightman
ID: 18198009
Hi mr_avril

Have our comments assisted you? If not, please can you provide some feedback, otherwise have a look at http://www.experts-exchange.com/help.jsp#hs5 for information on closing questions.

Regards
Nightman
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now