Help please creating a timer form a Internet cafe

wicked14

Member
Joined
Feb 13, 2012
Messages
9
Programming Experience
Beginner
im trying to do is countdown timer.already done with the start time and stop time but when it comes to the pause time and resume cant seem to make it work, what i did was put on the event click on my pause button was add a timer1.enabled = false and on the resume button timer1.enabled true, it does it job pausing the running time, but when i resume for example, i pause at a time of 05:30 for 9 seconds then resume the timer resumes at 5:21, (im making a countdown timer here) ,what i want to happen is that, when i resume, it will resume from 5:31 then continue counting down to 5:30,5:29 . . . . an so on, please check my code. and hope u understand. thanks in advance..

Public Class Form1

Dim TimeEnd, TimeStart, TimeStop As New DateTime
Dim isStop, isPause As Boolean
Dim form02 As New Form2
Dim foo, TimePause, ElapseTime, TotalTimePaused As New TimeSpan
Dim h, m, s As Integer


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = False
TextBox1.Text = "0" : TextBox2.Text = "0" : TextBox3.Text = "0"

Button6.Hide()
End Sub


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

If Timer1.Interval <> 100 Then Timer1.Interval = 100
If DateTime.Now > TimeEnd Then
TextBox5.Text = "Time End"
Timer1.Stop()

Else

If isStop = False And isPause = False Then
foo = TimeEnd - DateTime.Now
TextBox5.Text = String.Format("{0:D2}:{1:D2}:{2:D2}", _
foo.Hours, foo.Minutes, foo.Seconds)

End If
TextBox6.Text = TimeStart.ToString("hh:mm" & " " & "tt")

If isStop Then
TextBox4.Text = TimeStop.ToString("hh:mm" & " " & "tt")
Else

TextBox4.Text = TimeEnd.ToString("hh:mm" & " " & "tt")
End If
TextBox1.Text = "0" : TextBox2.Text = "0" : TextBox3.Text = "0"
End If

End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'START
Button1.Hide()
Timer1.Enabled = True
If Not Integer.TryParse(TextBox1.Text, h) OrElse _
Not Integer.TryParse(TextBox2.Text, m) OrElse _
Not Integer.TryParse(TextBox3.Text, s) Then
'bad input data
Exit Sub
End If
TimeEnd = DateTime.Now.AddHours(h).AddMinutes(m).AddSeconds(s)
TimeStart = DateTime.Now
TimeOfDay = DateTime.Now
Timer1.Interval = 1
Timer1.Start()
isStop = False

End Sub


Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'STOP
isStop = True
TimeStop = DateTime.Now


End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
isPause = True
Timer1.Enabled = False

Button1.Hide()
Button6.Show()
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
'RESUME
If isPause = True Then
Timer1.Enabled = True
isPause = False
End If
End Sub
End Class
 
Back
Top