954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Countdown Timer Help

Public Class frm_Main
    Private Sub btn_Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Start.Click
        Timer1.Start()
    End Sub
    Private Sub btn_Stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Stop.Click
        Timer1.Stop()
    End Sub
    Private Sub btn_Reset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Reset.Click
        tbx_Min.Text = "10"
        tbx_Sec.Text = "00"
        tbx_MilSec.Text = "00"
        Timer1.Stop()
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Do Until tbx_Min.Text = "00"
            Do Until tbx_Sec.Text = "00"
                Do Until tbx_MilSec.Text = "00"
                    Dim MilSec1 As Integer
                    MilSec1 = tbx_MilSec.Text
                    MilSec1 = MilSec1 - 1
                    tbx_MilSec.Text = MilSec1
                Loop
                Dim Sec1 As Integer
                Sec1 = tbx_Sec.Text
                Sec1 = Sec1 - 1
                tbx_Sec.Text = Sec1
            Loop
            Dim Min1 As Integer
            Min1 = tbx_Min.Text
            Min1 = Min1 - 1
            tbx_Min.Text = Min1
        Loop
        Console.Beep()
    End Sub
End Class


So far, this is my code. I am designing a Customizable Youtube Countdown Timer, and I am having some issues.
Whenever I start up the Form and press the "btn_Start" Button, the entire form freezes, and requires to be shutdown from Visual Basic Express 2010, where I am working, or through Task Manager.

Just in case... btn_ is my prefix for Buttons
tbx_ is my prefix for Textboxes

Please help me, because my friends and I currently need this form to work...

RedexProGamma
Newbie Poster
23 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

Your textbox is never going to equal "00". It will equal "0" however when it counts down (1 - 1 = 0, 1 - 1 != 00).
Also, at no point do you reset the seconds away from 00. E.g. 10.00.00 minus 1 sec doesn't seem to become 9.59.00 in your code.

hericles
Practically a Posting Shark
823 posts since Nov 2007
Reputation Points: 136
Solved Threads: 167
 

Thank you for your reply hericles, but can you deliberate further into how I can fix this problem?

RedexProGamma
Newbie Poster
23 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

You need to provide starting values for the millisecond and second when the countdown starts annd then resent those values again once a loop is finished. Inside the seconds loop reset the millisecond control to 100 after decreasing the seconds by 1 (otherwise the next millisecond loop has nothing to do), then reset the seconds to 60 after decreasing the minutes by 1.
Change your loop final to check for "0" instead of "00" to test it. You can also add code in to display "00" but check for "0" later if you want the digital clock look.

hericles
Practically a Posting Shark
823 posts since Nov 2007
Reputation Points: 136
Solved Threads: 167
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: