Results 1 to 6 of 6

Thread: Help... Question about Stopwatch program...

  1. #1

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524

    Post

    Dear All..

    I need help in order to make a stopwatch program...
    I confuse about the time set... Could anyone help me ???

    Thx...

    Wille
    Junior VB Programmer

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305

    Post

    heehee. I mean use a watch like you wear on your wrist to time it. It would be easier than writing the program.

  3. #3

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524

    Post

    Sorry...
    But, what do u mean by that Bob ???

    Could u explain it to me ???

    thx..

    Wille

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    Try:

    In a Form with a CommandButton and a Timer Control..
    Code:
    Private Sub Command1_Click()
        Timer1.Tag = "X"
        Timer1.Enabled = (Command1.Caption = "Start")
        Command1.Caption = IIf(Command1.Caption = "Start", "Stop", "Start")
    End Sub
    
    Private Sub Form_Load()
        Command1.Default = True
        Command1.Caption = "Start"
        Timer1.Enabled = False
        Timer1.Interval = 10
    End Sub
    
    Private Sub Timer1_Timer()
        Static tTimer As Single
        If Len(Timer1.Tag) Then
            tTimer = Timer
            Timer1.Tag = ""
        End If
        Caption = Format((Timer - tTimer), "Standard")
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

  5. #5

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524

    Post

    Thx Mr. Aaron...

    I've tried your code, and it works...
    but... I want to ask again... How can I set the time into zero again (when the time has reach 60 seconds) ???
    and if I want to format the output into hh:mm:ss, how can I do it ???

    Thx.....

    Wille

  6. #6
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    Modify the Timer Event in the Following Way:
    Code:
    Private Sub Timer1_Timer()
        Static tTimer As Single
        Dim tSecs As Single
        If Len(Timer1.Tag) Then
            tTimer = Timer
            Timer1.Tag = ""
        End If
        tSecs = Timer - tTimer
        Caption = Format(TimeSerial(0, 0, tSecs), "HH:MM:SS") & "." & Format((tSecs - Int(tSecs)) * 100, "00")
    End Sub
    N.B. This will only count to ~9hrs as the TimeSerial Function Requires an Integer

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width