Hello Guys,

I need your help, ill try to fix this almost 2 weeks, but no success, i want to make a countdown timer from hour to minutes to seconds, example: 01:20:10, using that format, i want to make a countdown timer, and this is my code, but no luck. T,I.A.

Public Class countdown

    Private Sub btnstart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstart.Click
        Timer1.Enabled = True
        lblhours.Text = txthours.Text
        lblmins.Text = txtmins.Text
        lblsecs.Text = txtsecs.Text

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Static sec, min, hour As Double

        sec = Val(lblsecs.Text)
        sec -= 1
        If sec <= 60 And sec >= 10 Then

            lblsecs.Text = sec
        ElseIf sec <= 10 And sec >= 1 Then
            lblsecs.Text = "0" & sec
        ElseIf sec = "00" Then
            lblsecs.Text = "00"

        End If
        If lblsecs.Text = "00" Then
            min = Val(lblmins.Text)
            min -= 1
        ElseIf min <= 60 And min >= 10 Then

            lblmins.Text = min
        ElseIf min <= 10 And min >= 1 Then
            lblmins.Text = "0" & min
        ElseIf min = "00" Then
            lblmins.Text = "00"

        End If
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick

    End Sub
End Class

Thanks in Advance Guys, I really need to fix it ASAP.
More Power Guys! :)

You can use the following example. only make sure that the interval property of the timer control is 1000 miliseconds

Public Class Form1
    Dim sec As Integer = 0
    Dim min As Integer = 0
    Dim hr As Integer = 0
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Label1.Text = "00"
        Label2.Text = "00"
        Label3.Text = "00"
        Timer1.Enabled = True
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = False
    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        sec += 1
        If sec = 60 Then
            min += 1
            sec = 0
        End If

        If min = 60 Then
            hr += 1
            min = 0
        End If

        Label1.Text = sec & " Sec"
        Label2.Text = min & " min"
        Label3.Text = hr & " hour"
    End Sub
End Class

Hope it can help you.

Thank you for your help sir, but your codes is all about stop watch, but i need is countdown timer, hehe, how can i fix that using your codes? change (+) to (-)? ehehe

Look at the example at https://msdn.microsoft.com/en-us/library/dd492144.aspx?f=255&MSPPError=-2147217396

While your code is yours I see problems aplenty that you need to address one by one. I would like to see you
1. Set your countdown variable before you enabled the timer.
2. Just use one countdown variable then convert to HH;MM;SS for display.
3. Disable the timer when it hits zero. Yours looks to keep running.

Sorry!
The codes should be

Public Class Form1
    Dim sec As Double = 5
    Dim min As Double = 3
    Dim hr As Double = 1
    Dim cursec As Double = 0
    Dim curmin As Double = 0
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Label1.Text = String.Format("{0} : {1} : {2}", Format(hr, "00"), Format(min, "00"), Format(sec, "00"))

        cursec = sec + (min + (hr * 60)) * 60

        Timer1.Enabled = True
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = False
    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick

        cursec -= 1
        If cursec=0 then
            Label1.Text ="00 : 00 : 00"
             Timer1.Enabled=False
        End If

        curmin = Math.Floor(cursec / 60)
        hr = Math.Floor(curmin / 60)
        min = curmin - hr * 60
        sec = cursec - curmin * 60

        Label1.Text = String.Format("{0} : {1} : {2}", Format(hr, "00"), Format(min, "00"), Format(sec, "00"))

    End Sub
End Class

thanks sir, may i ask if i use 3 label for the out of my countdown timer and 3 textbox which is you can input the time of my count down. sample label1 is for hour, label 2 is for minutes and label3 for seconds, and the value of textbox. textbox1 is for hour, textbox2 is for minutes and textbox3 is for minutes.

Hera countdown times is displayed in Label1, you can show Hr, Min, & Sec in different Label.
If you try to get the initial value from textboxs and display them in different labels the codes should be

Public Class Form1
    Dim cursec As Double = 0
    Dim curmin As Double = 0
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Label1.Text =  Format(Val(TextBox1.Text), "00") & "Hours"
        Label2.Text =  Format(Val(TextBox2.Text), "00") & "Minutes"
        Label2.Text =  Format(Val(TextBox3.Text), "00") & "Seconds"

        cursec = Val(TextBox3.Text) + (Val(TextBox2.Text) + (Val(TextBox1.Text) * 60)) * 60
        Timer1.Enabled = True
    End Sub
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = False
    End Sub
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        cursec -= 1
        If cursec=0 then
            Label1.Text =   "00 Hours"
            Label2.Text =  "00 Minutes"
            Label3.Text =  "00 Seconds"
            Timer1.Enabled=False
        End If

        curmin = Math.Floor(cursec / 60)

        Label1.Text = Format(Math.Floor(curmin / 60), "00") & "Hours"
        Label2.Text = Format(curmin - Val(Label1.Text) * 60, "00) & "Minutes"
        Label2.Text = Format(cursec - curmin * 60, "00") & "Seconds"

    End Sub
End Class

Hope it can help you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.