Timer Question

desperado

Well-known member
Joined
Oct 7, 2006
Messages
68
Programming Experience
Beginner
Hi if anyone could help with the following, i would appreciate it:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnActivate.Click
If btnActivate.Text = "Stop" Then
btnActivate.Text = "Start"
Timer1.Enabled = False
Else
btnActivate.Text = "Stop"
Timer1.Enabled = True
End If
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static Dim iPhase As Integer = 0
iPhase = iPhase + 1
If iPhase = 24 Then
iPhase = 1
End If
txtNow.Text = Now.ToLongTimeString & " " & iPhase
End Sub

The above is a coding which makes a timer start running on and off. The text also changes in the command button. If some1 could help me with the following code i would be greatful. I need help as i have another text box and every second that has passed on the timer i want to be shown in the text box. For example if i turn it on and off and it is for 5 second i want 5 displayed in the text box.

Thanks in advance
 

lingsn

Well-known member
Joined
Nov 16, 2006
Messages
287
Programming Experience
Beginner
I think is something like this

Code:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] tsTimespan [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] TimeSpan
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] start_time [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DateTime
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] stop_time [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DateTime
[/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] btnActivate_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] btnActivate.Click
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] btnActivate.Text = "Stop" [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]btnActivate.Text = "Start"
Timer1.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2]stop_time = Now
tsTimespan = stop_time.Subtract(start_time)
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].TextBox2.Text = tsTimespan.TotalSeconds.ToString("0")
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]start_time = Now
btnActivate.Text = "Stop"
Timer1.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
 
Top Bottom