Results 1 to 7 of 7

Thread: [RESOLVED] Triple Stopwatch

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    84

    Resolved [RESOLVED] Triple Stopwatch

    Hey,

    Okay I'm trying to make this (using VB6.0):

    - A form with three labels, and a Start button beneath each label. There's also one Stop and one Exit button.
    - All the three labels are stopwatches showing 00:00:00 (hh:mm:ss).
    - When a Start button is pushed the stopwatch is started on the label above.
    - Also, pressing a Start button will stop all other stopwatches. (If they are on, that is)

    I already searched these forums for a similar topic, found a few but got no help from them. So if you have any quidelines for this project, I'd approciate your help!

    I'm quite new to VB and haven't coded anything in a while.
    And no, I don't need a ready code, but a few hints here and there would be nice.

    Thanks, Rade

    PS Got to go now but will be back later today
    "Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
    - Linus Torvalds

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Triple Stopwatch

    VB Code:
    1. 'Add One Label Called lblstopwatch
    2. 'add one timer
    3. 'add two commandbutton and name them as cmdstarttimer and cmdstoptimer
    4. Dim Time2 As Date
    5.  
    6. Private Sub cmdstarttimer_Click()
    7.     Timer1.Enabled = True
    8. End Sub
    9.  
    10. Private Sub cmdstoptimer_Click()
    11.     Timer1.Enabled = False
    12. End Sub
    13.  
    14. Private Sub Form_Load()
    15.     Timer1.Interval = 1000 'timer time is 1 second
    16.     Timer1.Enabled = False
    17. End Sub
    18.  
    19. Private Sub Timer1_Timer()
    20.     lblstopwatch.Caption = Format$(Time2, "hh") & ":" & Format$(Time2, "nn") & ":" & Format$(Time2, "ss")
    21.     Time2 = DateAdd("s", 1, Time2)
    22. End Sub
    Last edited by danasegarane; Nov 15th, 2006 at 05:55 AM. Reason: Timer interval changed
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    84

    Re: Triple Stopwatch

    danasegarane, Thank You! That was exactly what I needed Or yes I made modifications but anyways, thanks!

    One thing still:
    If I want to have a Reset button that would put the stopwatch back to 00:00:00, is there an easier way to do it than this:
    VB Code:
    1. Private Sub cmdReset_Click()
    2.     Time2 = "00:00:00"
    3.     lblstopwatch.Caption = "00:00:00"
    4. End Sub
    Because if I put it like this:
    VB Code:
    1. Private Sub cmdReset_Click()
    2.     Time2 = "00:00:00"
    3.     lblstopwatch.Caption = Time2
    4. End Sub
    ...The label will show 0:00:00 instead of 00:00:00 for one second. Then it changes back.

    Thank you again
    Cheers, Rade
    "Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
    - Linus Torvalds

  4. #4
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Triple Stopwatch

    Dear Rade,
    Here is the modifed version
    VB Code:
    1. 'Add One Label Called lblstopwatch
    2. 'add one timer
    3. 'add two commandbutton and name them as cmdstarttimer and cmdstoptimer
    4. Dim Time2 As Date
    5.  
    6. Private Sub cmdreset_Click()
    7.     Timer1.Enabled = False 'stop the timer
    8.     lblstopwatch.Caption = "00:00:00" 'reset the label
    9.     Time2 = Date 'reset the date varriable
    10. End Sub
    11.  
    12. Private Sub cmdstarttimer_Click()
    13.     Timer1.Enabled = True 'start the timer
    14. End Sub
    15.  
    16. Private Sub cmdstoptimer_Click()
    17.     Timer1.Enabled = False 'stop the timer
    18. End Sub
    19.  
    20.  
    21. Private Sub Form_Load()
    22.  Timer1.Enabled = False
    23.  Timer1.Interval = 1000
    24.  lblstopwatch.Caption = "00:00:00" 'reset the label
    25. End Sub
    26.  
    27. Private Sub Timer1_Timer()
    28.     lblstopwatch.Caption = Format$(Time2, "hh") & ":" & Format$(Time2, "nn") & ":" & Format$(Time2, "ss")
    29.     Time2 = DateAdd("s", 1, Time2)
    30. End Sub
    Please mark you thread resolved using the Thread Tools as shown

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    84

    Re: Triple Stopwatch

    Oh, thank you again I Really approciate this!

    One last little tiny thing if you have time:
    When I start the timer it lasts 2 seconds before is shows 00:00:01. Is there any way to fix this? It's not that important but...

    Rade
    "Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
    - Linus Torvalds

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Triple Stopwatch

    replace this coding
    in your From
    VB Code:
    1. Private Sub Timer1_Timer()
    2.     Time2 = DateAdd("s", 1, Time2)
    3.     lblstopwatch.Caption = Format$(Time2, "hh") & ":" & Format$(Time2, "nn") & ":" & Format$(Time2, "ss")
    4. End Sub
    Please mark you thread resolved using the Thread Tools as shown

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    84

    Re: Triple Stopwatch

    Alright!
    Thank You for the help

    Rade
    "Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
    - Linus Torvalds

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