Solved

How to make hour/minutes/second counter

Posted on 2006-11-18
5
352 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

743 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

18 Experts available now in Live!

Get 1:1 Help Now