?
Solved

How to make hour/minutes/second counter

Posted on 2006-11-18
5
Medium Priority
?
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 86

Accepted Solution

by:
Mike Tomlinson earned 150 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! 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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

752 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