Jump to content
xisto Community
Sign in to follow this  
paulbacca

Countdown Timer

Recommended Posts

Hi all,Can you help me with the script below. I found this code on a old posting. I would like to able too input a value for hours and have that countdown also.ThanksPaul

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick        Dim hours As Integer = countminutes.Text        Dim minutes As Integer = countminutes.Text        Dim seconds As Integer = countseconds.Text        If hours = 0 And minutes = 0 And seconds = 0 Then            'MsgBox("Time Ended")            Timer1.Stop()        End If        If seconds = 0 Then            minutes -= 1            seconds += 60        End If        seconds -= 1        If minutes <> -1 Then            counthours.Text = minutes            countminutes.Text = minutes            countseconds.Text = seconds        End If    End Sub    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        If InStr(timetowait.Text, ":") Then            Dim time() As String            time = Split(timetowait.Text, ":", , CompareMethod.Text)            countminutes.Text = time(0)            countseconds.Text = time(1)            Timer1.Interval = 1000            Timer1.Start()        Else : MsgBox("You have to insert like this 1:10")        End If    End Sub

Edited by paulbacca (see edit history)

Share this post


Link to post
Share on other sites
Try thisCountdown Timer

Should be something similar to this:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick        Dim hours As Integer = counthours.Text        Dim minutes As Integer = countminutes.Text        Dim seconds As Integer = countseconds.Text        If hours = 0 And minutes = 0 And seconds = 0 Then            'MsgBox("Time Ended")            Timer1.Stop()        End If        If seconds = 0 Then            minutes -= 1            seconds += 60        End If        If minutes = 0 Then            hours -= 1            minutes += 60        End If        seconds -= 1        If minutes <> -1 Then            counthours.Text = hours            countminutes.Text = minutes            countseconds.Text = seconds        End If    End Sub    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        If InStr(timetowait.Text, ":") Then            Dim time() As String            time = Split(timetowait.Text, ":", , CompareMethod.Text)
            counthours.Text = time(0)            countminutes.Text = time(1)            countseconds.Text = time(2)            Timer1.Interval = 1000            Timer1.Start()        Else : MsgBox("You have to insert like this 1:20:30")        End If    End Sub

Share this post


Link to post
Share on other sites

Private Sub btnTimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimer.Click If InStr(timetowait.Text, ":") Then Dim time() As String time = Split(timetowait.Text, ":", , CompareMethod.Text) counthours.Text = time(0) countminutes.Text = time(0) countseconds.Text = time(1) Timer1.Interval = 1000 Timer1.Start() Else : MsgBox("You have to insert like this 00:00:00") End If End SubPrivate Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim hours As Integer = counthours.Text() Dim minutes As Integer = countminutes.Text Dim seconds As Integer = countseconds.Text If hours = 0 And minutes = 0 And seconds = 0 Then Timer1.Stop() MsgBox("Time Ended") MsgBox("Answer!") End If If minutes = 0 Then hours -= 1 minutes += 60 End If If seconds = 0 Then minutes -= 1 seconds += 60 End If seconds -= 1 If minutes <> -1 Then counthours.Text = hours countminutes.Text = minutes countseconds.Text = seconds End If End Sub

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.