Results 1 to 12 of 12

Thread: timer control ? *RESOLVED*

Threaded View

  1. #1

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    timer control ? *RESOLVED*

    I have been messn around with the folowing code and was wondering if there might be a better way to do what I am attempting to achieve.

    I two lables setup and two timers. The first timer counts in seconds and displays "00m 00." the second timer counts in milliseconds, and displays ".00s". The effect I am looking for is to see the milliseconds run.

    VB Code:
    1. 'Declare tCount
    2. Dim tCount As Integer
    3. Dim tCount2 As Integer
    4.  
    5. Private Function SecsToTime(Seconds As Integer) As String
    6. Dim Hours As Integer, Minutes As Integer
    7. 'Hours = Seconds \ 3600 'seconds in 1 hour
    8. 'Seconds = Seconds Mod 3600
    9. Minutes = Seconds \ 60 'seconds in 1 minute
    10. Seconds = Seconds Mod 60
    11. 'SecsToTime = Hours & "h: " & Format(Minutes, "00") & "m: " & Format(Seconds, "00.")
    12. SecsToTime = Hours & "m: " & Format(Seconds, "00.")
    13. End Function
    14. Private Function SecsToMill(Seconds As Integer) As String
    15. Seconds = Seconds Mod 60
    16. SecsToMill = Hours & Format(Seconds, "00") & "s:"
    17. End Function
    18.  
    19. Private Sub Command1_Click()
    20. Timer1.Enabled = False
    21. Timer2.Enabled = False
    22. End Sub
    23.  
    24. Private Sub Timer1_Timer()
    25. 'Increase the second count
    26. tCount = tCount + 1
    27. 'Me.Caption = tCount
    28. 'Get the formatted timing
    29. Label1.Caption = SecsToTime(tCount)
    30. End Sub
    31.  
    32. Private Sub Timer2_Timer()
    33. 'Increase the second count
    34. tCount2 = tCount2 + 1
    35. 'Me.Caption = tCount2
    36. 'Get the formatted timing
    37. Label2.Caption = SecsToMill(tCount2)
    38. End Sub
    39.  
    40. Private Sub Form_Load()
    41. 'Set the initial caption
    42. Label1.Caption = "00m: 00."
    43. Label2.Caption = "00s"
    44. 'Set the interval to ~1 second
    45. Timer1.Interval = 1000 'milliseconds = 1 second
    46. Timer2.Interval = 1 'milliseconds = 1/1000 second
    47. 'Reset the second counter
    48. tCount = 0
    49. End Sub
    Last edited by Navarone; Aug 8th, 2003 at 08:02 AM.
    He who never made a mistake never made a discovery?

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