Hi, everybody

I wonder if you can help me with a program in visual basic. I have to write a program that does a count down on the number of seconds you entered in the GUI I have most of the code and it basically has to countdown the seconds i type in the txtStart. Attached is the program design

This is what i have so far with the code. It converts seconds to hours and minutes and seconds, but it doesn't do the countdown

Here's my code :

PLEASE LET ME KNOW AS SOON AS POSSIBLE


THANK YOU :D

Public Class frmMain


    

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub tmrCountdown_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrCountdown.Tick
        Dim start As Integer
        Dim hours As Integer
        Dim minutes As Integer
        Dim seconds As Integer


        'input, read in the total number of seconds
        Integer.TryParse(txtStart.Text, start)

        'calculation
        hours = Int(start / 3600)
        minutes = (Int(start / 60)) - (hours * 60)
        seconds = Int(start Mod 60)




        If seconds = 60 Then
            minutes = minutes + 1
            seconds = 0
        End If

        If minutes = 60 Then
            minutes = 0
            hours = hours + 1
        End If

        'output
        lblHours.Text = hours.ToString()

        lblMinutes.Text = minutes.ToString()

        lblSeconds.Text = seconds.ToString()


        'ENABLE THE TIMER
        tmrCountdown.Enabled = True

       
    End Sub

    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click

    End Sub

    Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click

    End Sub

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        Dim start As Integer
        Dim hours As Integer
        Dim minutes As Integer
        Dim seconds As Integer


        'input, read in the total number of seconds
        Integer.TryParse(txtStart.Text, start)

        'calculation
        hours = Int(start / 3600)
        minutes = (Int(start / 60)) - (hours * 60)
        seconds = Int(start Mod 60)




        If seconds = 60 Then
            minutes = minutes + 1
            seconds = 0
        End If

        If minutes = 60 Then
            minutes = 0
            hours = hours + 1
        End If

        'output
        Hours.Text = hours.ToString()

        Minutes.Text = minutes.ToString()

        Seconds.Text = seconds.ToString()



        'ENABLE THE TIMER
        tmrCountdown.Enabled = True
    End Sub
End Class

Edited 6 Years Ago by WaltP: Added CODE Tags -- please use them

Attachments Countdown_Seconds.jpg 19.22 KB

Under your timer, subtract 1 second from your original start seconds criteria. Everytime the timer fires, another second is deducted from the previous value.

I have asked that your post be moved to .Net, this is currently in VB6.

This article has been dead for over six months. Start a new discussion instead.