Reset an integer
-
Hello all! I can't beleive I can't get this, but here it goes. I want to reset a integer number that used for a time. So at the top I have
Public mysec As Integer = 15
Then I have this for my timerPrivate Sub tmrGame_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGame.Tick Threading.Thread.SpinWait(1000) mysec = mysec - 1 lblcdClock.Text = ":" & mysec If mysec > 15 Then mysec = 0 End If If mysec = -1 Then tmrGame.Stop() lblcdClock.Text = ":" & 0 Threading.Thread.Sleep(2000) lblcdClock.Text = ":" & 15 End If End Sub
How can I reset "mysec" to 15 so when the time stops, and I start it agin, it start from 15? Using VS 2003. Thanks! Rudy -
Hello all! I can't beleive I can't get this, but here it goes. I want to reset a integer number that used for a time. So at the top I have
Public mysec As Integer = 15
Then I have this for my timerPrivate Sub tmrGame_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGame.Tick Threading.Thread.SpinWait(1000) mysec = mysec - 1 lblcdClock.Text = ":" & mysec If mysec > 15 Then mysec = 0 End If If mysec = -1 Then tmrGame.Stop() lblcdClock.Text = ":" & 0 Threading.Thread.Sleep(2000) lblcdClock.Text = ":" & 15 End If End Sub
How can I reset "mysec" to 15 so when the time stops, and I start it agin, it start from 15? Using VS 2003. Thanks! RudyThe method that starts the timer should reset the variable.
rudemusik wrote:
If mysec = -1
if mysec < 0 is a safer check to make, just in case. So, if it goes over 15, it gets reset to 0, and on the next iteration, it will end ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hello all! I can't beleive I can't get this, but here it goes. I want to reset a integer number that used for a time. So at the top I have
Public mysec As Integer = 15
Then I have this for my timerPrivate Sub tmrGame_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGame.Tick Threading.Thread.SpinWait(1000) mysec = mysec - 1 lblcdClock.Text = ":" & mysec If mysec > 15 Then mysec = 0 End If If mysec = -1 Then tmrGame.Stop() lblcdClock.Text = ":" & 0 Threading.Thread.Sleep(2000) lblcdClock.Text = ":" & 15 End If End Sub
How can I reset "mysec" to 15 so when the time stops, and I start it agin, it start from 15? Using VS 2003. Thanks! Rudykeep all your code inside inner loop and when the loop will end assign mysec=15 enclose this also inside an outer loop .use 2 while loop this will be better and give terminating condition in outer while loop ok
prem kumar singh
-
The method that starts the timer should reset the variable.
rudemusik wrote:
If mysec = -1
if mysec < 0 is a safer check to make, just in case. So, if it goes over 15, it gets reset to 0, and on the next iteration, it will end ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Hi Christian! It's actually counting down from 15. I have mysec = -1 so that a 0 will show. After the 0 shows, I set the label to 15. But it doesn't change my intger, so if it starts again, it will start with -1, -2 and so on. How can I change the 0 to a 15 as if if I were reloading the form to kick off the "Public mysec As Integer = 15" line. Thanks! Rudy
-
keep all your code inside inner loop and when the loop will end assign mysec=15 enclose this also inside an outer loop .use 2 while loop this will be better and give terminating condition in outer while loop ok
prem kumar singh
-
Hi Christian! It's actually counting down from 15. I have mysec = -1 so that a 0 will show. After the 0 shows, I set the label to 15. But it doesn't change my intger, so if it starts again, it will start with -1, -2 and so on. How can I change the 0 to a 15 as if if I were reloading the form to kick off the "Public mysec As Integer = 15" line. Thanks! Rudy
-
'Resetting' the value is as simple as mysec = 15, you should do this just before you start the countdown.