Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Dim StartTime As DateTime 'old current time
- Dim PauseTime As DateTime 'keep track of the time when the timer is paused
- Dim TotalTimePaused As TimeSpan 'The total amount of time paused
- Dim StartTime2 As DateTime 'old current time
- Dim PauseTime2 As DateTime 'keep track of the time when the timer is paused
- Dim TotalTimePaused2 As TimeSpan 'The total amount of time paused
- Private Sub BtnStart1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStart1.Click
- BtnStart1.Enabled = False
- BtnPause1.Enabled = True
- StartTime = DateTime.Now()
- Timer1.Start()
- End Sub
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- 'Subtract the current "Now" time from the start time
- 'and then subtract the total time paused
- Dim ElapsedTime As TimeSpan = DateAndTime.Now.Subtract(StartTime).Subtract(TotalTimePaused)
- Label2.Text = ElapsedTime.Hours.ToString.PadLeft(2, "0"c) + ":" + ElapsedTime.Minutes.ToString.PadLeft(2, "0"c) + ":" + ElapsedTime.Seconds.ToString.PadLeft(2, "0"c)
- 'And if you wanted the total elapsed time from time of start then
- 'subtract the current "Now" time from the start time only.
- End Sub
- Private Sub BtnPause1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPause1.Click
- If Timer1.Enabled = False Then
- BtnPause1.Text = "Pause"
- 'Add to the total time paused; the current time minus the
- 'time of pause. this will be the total amount of time
- 'paused so you can subtract it from the total amount of
- 'time since the start button was pressed
- TotalTimePaused = TotalTimePaused.Add(DateAndTime.Now.Subtract(PauseTime))
- Timer1.Enabled = True
- Else
- BtnPause1.Text = "Resume"
- Timer1.Enabled = False
- 'Set the pause time so it can be
- 'calculated to the total time paused.
- 'when the timer is resumed
- PauseTime = DateAndTime.Now
- End If
- End Sub
- Private Sub BtnStop1_Click(sender As Object, e As EventArgs) Handles BtnStop1.Click
- Timer1.Stop()
- BtnStart1.Enabled = True
- End Sub
- 'Private Sub BtnStart2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStart2.Click
- ' BtnStart2.Enabled = False
- ' BtnPause2.Enabled = True
- ' StartTime2 = DateTime.Now()
- ' Timer2.Start()
- 'End Sub
- 'Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
- ' 'Subtract the current "Now" time from the start time
- ' 'and then subtract the total time paused
- ' Dim ElapsedTime2 As TimeSpan = DateAndTime.Now.Subtract(StartTime2).Subtract(TotalTimePaused2)
- ' Label4.Text = ElapsedTime2.Hours.ToString.PadLeft(2, "0"c) + ":" + ElapsedTime2.Minutes.ToString.PadLeft(2, "0"c) + ":" + ElapsedTime2.Seconds.ToString.PadLeft(2, "0"c)
- ' 'And if you wanted the total elapsed time from time of start then
- ' 'subtract the current "Now" time from the start time only.
- 'End Sub
- 'Private Sub BtnPause2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPause2.Click
- ' If Timer1.Enabled = False Then
- ' BtnPause2.Text = "Pause"
- ' 'Add to the total time paused; the current time minus the
- ' 'time of pause. this will be the total amount of time
- ' 'paused so you can subtract it from the total amount of
- ' 'time since the start button was pressed
- ' TotalTimePaused2 = TotalTimePaused2.Add(DateAndTime.Now.Subtract(PauseTime2))
- ' Timer2.Enabled = True
- ' Else
- ' BtnPause2.Text = "Resume"
- ' Timer2.Enabled = False
- ' 'Set the pause time so it can be
- ' 'calculated to the total time paused.
- ' 'when the timer is resumed
- ' PauseTime2 = DateAndTime.Now
- ' End If
- 'End Sub
- 'Private Sub BtnStop2_Click(sender As Object, e As EventArgs) Handles BtnStop2.Click
- ' If Timer2.Enabled = False Then
- ' BtnStart2.Enabled = True
- ' Else
- ' BtnStop1.Enabled = False
- ' End If
- 'End Sub
- End Class
Add Comment
Please, Sign In to add comment