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:
'Declare tCount Dim tCount As Integer Dim tCount2 As Integer Private Function SecsToTime(Seconds As Integer) As String Dim Hours As Integer, Minutes As Integer 'Hours = Seconds \ 3600 'seconds in 1 hour 'Seconds = Seconds Mod 3600 Minutes = Seconds \ 60 'seconds in 1 minute Seconds = Seconds Mod 60 'SecsToTime = Hours & "h: " & Format(Minutes, "00") & "m: " & Format(Seconds, "00.") SecsToTime = Hours & "m: " & Format(Seconds, "00.") End Function Private Function SecsToMill(Seconds As Integer) As String Seconds = Seconds Mod 60 SecsToMill = Hours & Format(Seconds, "00") & "s:" End Function Private Sub Command1_Click() Timer1.Enabled = False Timer2.Enabled = False End Sub Private Sub Timer1_Timer() 'Increase the second count tCount = tCount + 1 'Me.Caption = tCount 'Get the formatted timing Label1.Caption = SecsToTime(tCount) End Sub Private Sub Timer2_Timer() 'Increase the second count tCount2 = tCount2 + 1 'Me.Caption = tCount2 'Get the formatted timing Label2.Caption = SecsToMill(tCount2) End Sub Private Sub Form_Load() 'Set the initial caption Label1.Caption = "00m: 00." Label2.Caption = "00s" 'Set the interval to ~1 second Timer1.Interval = 1000 'milliseconds = 1 second Timer2.Interval = 1 'milliseconds = 1/1000 second 'Reset the second counter tCount = 0 End Sub




Reply With Quote