• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

Producing a Stop watch.

I want to produce a stopwatch, (i.e. a timer) able to display minutes, seconds, miliseconds.  How will I get round doing this?

Thanks.
0
n-generation
Asked:
n-generation
  • 2
1 Solution
 
vinnyd79Commented:
actually doesn't look like that example handles milliseconds. You could try this link under downloads:

http://www.mvps.org/ccrp/

There is a hi-performance timer control.
0
 
robertleesCommented:
Put the following declaration in a module:

Public Declare Function GetTickCount Lib "kernel32" () As Long

On your form, place a timer control (Timer1) with an interval of 1 (ie, 1 millisecond), and a label (Label1).

Private Sub Timer1_Timer()
    Static lngStart As Long
    Dim ms As Long
    Dim h As Long
    Dim m As Long
    Dim s As Long
   
    If lngStart = 0 Then
        lngStart = GetTickCount()  'first time
    End If
   
    'milliseconds since start
    ms = GetTickCount() - lngStart
   
    'break milliseconds into parts
    s = Int(ms / 1000)
    ms = ms - (s * 1000)
   
    m = Int(s / 60)
    s = s - (m * 60)
   
    h = Int(m / 60)
    m = m - (h * 60)
   
    'show current elapsed time
    Label1.Caption = Format(h) & ":" & Format(m, "00") & ":" & Format(s, "00") & "." & Format(ms, "000")
End Sub
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now