Countdown Program

Making a Countdown program thats customizable

Page 1 of 1

2 Replies - 1673 Views - Last Post: 16 July 2009 - 02:14 PM Rate Topic: -----

#1 ixoye800  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 20-June 09

Countdown Program

Post icon  Posted 16 July 2009 - 12:26 PM

I have been working on a countdown program that using numeric-up-down sets:

Days
Hours
Minutes
Seconds
Milliseconds

The numeric Up Downs set the value to a Label that counts down the Numbers:

Dim IDays As Integer
		IDays = Integer.Parse(NumericUpDown4.Value)
		Days.Text = IDays
		Dim IHours As Integer
		IHours = Integer.Parse(NumericUpDown3.Value)
		Hours.Text = IHours
		Dim IMinutes As Integer
		IMinutes = Integer.Parse(NumericUpDown2.Value)
		Minutes.Text = IMinutes
		Dim ISeconds As Integer
		ISeconds = Integer.Parse(NumericUpDown1.Value)
		Seconds.Text = ISeconds
		Milliseconds.Text = 10
		Timer1.Enabled = True



However, i had a problem in which the numbers, even if they were 0 were subtracted, resulting in negative numbers:

So i wrote some code using a timer that subtracts in milliseconds:

i cant insert the timecode:

e.g.

10 milliseconds in a seconds
60 seconds in a minute
60 minutes in an hour
24 hours in a day
99 days max

So it counts everything as milliseconds.

Here is the code:


 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
		If Milliseconds.Text = 0 Then
			If Seconds.Text = 0 Then
				If Minutes.Text = 0 Then
					If Hours.Text = 0 Then
						If Days.Text = 0 Then
							Timer1.Enabled = False
							Milliseconds.Text = "*"
							Seconds.Text = "*"
							Minutes.Text = "*"
							Hours.Text = "*"
							Days.Text = "*"
						Else
							Days.Text = Days.Text - Val(1)
						End If
					Else
						Hours.Text = Hours.Text - Val(1)
					End If
				Else
					Minutes.Text = Minutes.Text - Val(1)
				End If
			Else
				Seconds.Text = Seconds.Text - Val(1)
			End If
		Else
			Milliseconds.Text = Milliseconds.Text - Val(1)
		End If
	End Sub



Timer1 interval is 100

Thanks for any help.

Is This A Good Question/Topic? 0
  • +

Replies To: Countdown Program

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Countdown Program

Posted 16 July 2009 - 12:48 PM

Here is part of your code:

					If Hours.Text = 0 Then
						If Days.Text = 0 Then
							Timer1.Enabled = False
							Milliseconds.Text = "*"
							Seconds.Text = "*"
							Minutes.Text = "*"
							Hours.Text = "*"
							Days.Text = "*"
						Else
							Days.Text = Days.Text - Val(1)
						End If
					Else
						Hours.Text = Hours.Text - Val(1)
					End If



Now, let's take a look at the same code but without that inner if statement:

					If Hours.Text = 0 Then

					Else
						Hours.Text = Hours.Text - Val(1)
					End If



See? You aren't doing anything if the hours.text = 0. Same goes for other if statements there except the one for days.
So inside that statement you should be doing something like this:

					If Hours.Text = 0 Then
						Hours.Text = 23
					Else
						Hours.Text = Hours.Text - Val(1)
					End If


Was This Post Helpful? 0
  • +
  • -

#3 ixoye800  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 20-June 09

Re: Countdown Program

Posted 16 July 2009 - 02:14 PM

View Postjanne_panne, on 16 Jul, 2009 - 11:48 AM, said:

Here is part of your code:

					If Hours.Text = 0 Then
						If Days.Text = 0 Then
							Timer1.Enabled = False
							Milliseconds.Text = "*"
							Seconds.Text = "*"
							Minutes.Text = "*"
							Hours.Text = "*"
							Days.Text = "*"
						Else
							Days.Text = Days.Text - Val(1)
						End If
					Else
						Hours.Text = Hours.Text - Val(1)
					End If



Now, let's take a look at the same code but without that inner if statement:

					If Hours.Text = 0 Then

					Else
						Hours.Text = Hours.Text - Val(1)
					End If



See? You aren't doing anything if the hours.text = 0. Same goes for other if statements there except the one for days.
So inside that statement you should be doing something like this:

					If Hours.Text = 0 Then
						Hours.Text = 23
					Else
						Hours.Text = Hours.Text - Val(1)
					End If



Thanks, Works Perfectly!!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1