0

Basically what I want is to have the timer be reset back to 3 sec once the Reset button is clicked. Preferably, I want the code to be in the same sub as the timer, though any better ideas are most welcomed. I've already put in comments where i want the code to be... thanks in advance for your help :)

Here's the part of the code...

Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
        Static CountDown As New TimeSpan(0, 1, 0)
        Dim Time0 As New TimeSpan(0, 0, 0)

        CountDown = CountDown.Subtract(New TimeSpan(0, 0, 1))
        If CountDown.Equals(Time0) Then
            Timer.Stop()
            CountDown = New TimeSpan(0, 3, 0)
        End If

        lblTimer.Text = CountDown.ToString

        If CountDown <= New TimeSpan(0, 0, 30) Then
            If lblTimer.ForeColor = Color.White Then
                lblTimer.ForeColor = Color.Red
            Else
                lblTimer.ForeColor = Color.White
            End If
        End If

        'check if btnReset is clicked
End Sub

Edited by ITfav: n/a

2
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by TomW
0

Move your static countdown variable to form level.
In the btnReset click event, assign the new time value of 3 secons to your form level variable (m_CountDown)
And re-enable your timer if necessary

Edited by TomW: n/a

0

erm... how do i do tt? I tried tt and had an error... " 'Static' is not a valid on a member variable declaration"

0

The variable will no longer need to be "Static" since its scope is in existence for the life of the form itself. This would be refered to as a module level variable (hence the "m_" prefix to signify its scope) or form level.

Public Class Form1

Dim m_CountDown As New TimeSpan(0, 1, 0)

Private Sub Form1_Load()
...
End Sub
End Class
0

The variable will no longer need to be "Static" since its scope is in existence for the life of the form itself. This would be refered to as a module level variable (hence the "m_" prefix to signify its scope) or form level.


Public Class Form1

Dim m_CountDown As New TimeSpan(0, 1, 0)

Private Sub Form1_Load() ... End Sub End Class[Code=VB]

Public Class Form1

Dim m_CountDown As New TimeSpan(0, 1, 0)

Private Sub Form1_Load()
...
End Sub
End Class

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.