This Code allows you too countdown seconds and minutes but im not sure how to add hours or maybe even days to it:(
===========================================================================================

Imports System.Threading.Thread

Public Class Form1

    Private Sub Button1_Click(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

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim minutes As Integer = countminutes.Text
        Dim seconds As Integer = countseconds.Text
        If 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
            countminutes.Text = minutes
            countseconds.Text = seconds
        End If
    End Sub
End Class

=========================================================================================if anyone can help me it would be appreciated:icon_cry:

Recommended Answers

All 7 Replies

The easiest and savest way is this:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
		Dim tstan As TimeSpan
		If Not TimeSpan.TryParse(txtTime.Text, tstan) Then
			MsgBox("Please enter the time in format d:h:m:s")
			Return
		End If
		Timer1.Interval = 1000
		Timer1.Start()
	End Sub

	Private Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick
		Dim tspan As TimeSpan = TimeSpan.Parse(txtTime.Text)
		If tspan.Days = 0 AndAlso tspan.Hours = 0 AndAlso tspan.Minutes = 0 AndAlso tspan.Seconds = 0 Then
			Timer1.Stop()
			Return
		End If
		txtTime.Text = tspan.Subtract(TimeSpan.FromSeconds(1)).ToString
	End Sub

WOw thanks much better than thee old one
Im gona check on it now

How would i beable to show Days , hours , minutes ,seconds in diffrent textboxes
When they count down ofcourse so tht each of them are seprate

Private Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick
	Dim tspan As TimeSpan = TimeSpan.Parse(txtTime.Text)
	If tspan.Days = 0 AndAlso tspan.Hours = 0 AndAlso tspan.Minutes = 0 AndAlso tspan.Seconds = 0 Then
		Timer1.Stop()
		Return
	End If
        Dim tmpSpan as timeSpan = tspan.Subtract(TimeSpan.FromSeconds(1))
	txtDays.Text = tmpSpan.Days.ToString
        txtHours.Text = tmpSpan.Hours.ToString 'and so on
	End Sub

:-/
MMMM it seems its not working it does show the numbers but doesnt count down

Sorry my fault. Here a working snippet:

Public Class Form1

	Private pCurrentCounter as timespan

	Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
		Dim tspan As TimeSpan
		If Not TimeSpan.TryParse(txtTime.Text, tspan) Then
			MsgBox("Please enter the time in format d:h:m:s")
			Return
		End If
		pCurrentCounter=tspan
		Timer1.Interval = 1000
		Timer1.Start()
	End Sub

	Private Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick
		If pCurrentCounter.Days = 0 AndAlso pCurrentCounter.Hours = 0 AndAlso pCurrentCounter.Minutes = 0 AndAlso pCurrentCounter.Seconds = 0 Then
			Timer1.Stop()
			Return
		End If
		pCurrentCounter = pCurrentCounter.Subtract(TimeSpan.FromSeconds(1))
		txtDays.Text=pCurrentCounter.Days.ToString
		txtHours.Text=pCurrentCounter.Hours.ToString
		txtMinutes.Text=pCurrentCounter.Minutes.ToString
		txtSeconds.Text=pCurrentCounter.Seconds.ToString
	End Sub
End Class

Thank you For your Help GEEKBYCHOICE:)
Yu Really should Get a Medal;)

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.