Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Reset an integer

Reset an integer

Scheduled Pinned Locked Moved Visual Basic
questionvisual-studio
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rudemusik
    wrote on last edited by
    #1

    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 timer Private 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

    C L 2 Replies Last reply
    0
    • R rudemusik

      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 timer Private 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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      R 1 Reply Last reply
      0
      • R rudemusik

        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 timer Private 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

        L Offline
        L Offline
        lucky prem
        wrote on last edited by
        #3

        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

        R 1 Reply Last reply
        0
        • C Christian Graus

          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 )

          R Offline
          R Offline
          rudemusik
          wrote on last edited by
          #4

          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

          T 1 Reply Last reply
          0
          • L lucky prem

            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

            R Offline
            R Offline
            rudemusik
            wrote on last edited by
            #5

            Hi Lucky! What do you ean by inner loop? Thanks! Rudy

            1 Reply Last reply
            0
            • R rudemusik

              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

              T Offline
              T Offline
              TwoFaced
              wrote on last edited by
              #6

              'Resetting' the value is as simple as mysec = 15, you should do this just before you start the countdown.

              R 1 Reply Last reply
              0
              • T TwoFaced

                'Resetting' the value is as simple as mysec = 15, you should do this just before you start the countdown.

                R Offline
                R Offline
                rudemusik
                wrote on last edited by
                #7

                Thanks Everybody! I finally got it. I actually had to put "mysec = 15" at the end of the countdown. Thanks again! Rudy

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups