title: Timer to count down in VB.Net 2010?
body: <p>I'm trying to use a timer to count down from a specified time I choose with the time being separated into minutes and seconds using the format <strong>MM:SS</strong> and then stop when the time reaches <strong>00:00</strong>.</p>
  
  <p>So far I've used a previous answer that was found on here and modified it to the best of my knowledge with counting down although I've hit a snag in which when the timer successfully starts counting down, it's delayed and out of sync when counting down the minutes.</p>
  
  <p>For example, counting down from 120 seconds;</p>
  
  <p><code>02:00</code> >
  <code>02:59</code> >
  <code>02:58</code> >
  <code>02:57</code> >
  <code>02:56</code> >
  <code>02:55</code></p>
  
  <p>And then when continuing to count down past 90 seconds under the same test;</p>
  
  <p><code>02:30</code> >
  <code>01:29</code> >
  <code>01:28</code> >
  <code>01:27</code> >
  <code>01:26</code> >
  <code>01:25</code></p>
  
  <p>When the countdown reaches <strong>00</strong> or <strong>30</strong> seconds, it incorrectly displays the minutes left and can't understand or figure out how to fix it.</p>
  
  <p>Here is my code for my Counting Timer;</p>
  
  <pre><code>Private Sub tmrCountdown_Tick(ByVal sender As System.Object, _
                                ByVal e As System.EventArgs) _
                            Handles tmrCountdown.Tick
  
      SetTime = SetTime - 1
      lblTime.Text = FormatTime(SetTime)
  
      If SetTime = 0 Then
          tmrCountdown.Enabled = False
      End If
  
  End Sub
  </code></pre>
  
  <p>Here is my code for the Function formatting the time;</p>
  
  <pre><code>Public Function FormatTime(ByVal Time As Integer) As String
      Dim Min As Integer
      Dim Sec As Integer
  
      'Minutes
      Min = ((Time - Sec) / 60) Mod 60
  
      'Seconds
      Sec = Time Mod 60
  
      Return Format(Min, "00") &amp; ":" &amp; Format(Sec, "00")
  
  End Function
  </code></pre>
  
  <p>And here is my code for the Form Load;</p>
  
  <pre><code>Private Sub frmSinglePlayer_Load(ByVal sender As System.Object, _
                                   ByVal e As System.EventArgs) _
                               Handles MyBase.Load
  
      'Setting the time.
      SetTime = 120
      lblTime.Text = FormatTime(SetTime)
      tmrCountdown.Enabled = True
  
  End Sub
  </code></pre>
  
  <p>I've set;</p>
  
  <pre><code>    Dim SetTime As Integer
  </code></pre>
  
  <p>At the top of my Public Class so I am able to input a specified time into the countdown timer. This is probably something incredibly silly and I can't figure out what it is.</p>
  
  <p>Any help is greatly appreciated and please bare in mind, I am a beginner at programming and get easily confused with large walls of code. (I can barely understand the Function as it is.)</p>
  
  <p>Thank you for helping!</p>