Solved

How to make hour/minutes/second counter

Posted on 2006-11-18
5
356 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 86

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 127
Can we place a tooltip on the actual vb6 form 5 51
Passing a Text Box name to a Sub 6 102
VB6 ListBox Question 4 56
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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

733 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