Solved

Count down clock

Posted on 2015-01-26
6
84 Views
Last Modified: 2015-01-26
I need to create a countdown clock that counts down from a starting value of 60 minutes and shows the progress of the countdown in a label field.  

As an example it would start with the label showing 1:00:00 and the count down every second form there showing the progress along the way.  

I would appreciate any help anybody could provide me.

Thanks
0
Comment
Question by:Mike_Stevens
6 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40570544
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40570603
Can I ask you why you need it? Because if you want a count down on a screen, it already exist! Check the "break" feature of https://technet.microsoft.com/en-us/sysinternals/bb897434
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 40570618
Since that looks like some kind of programming homework, I'll try to point you the rough way I would ímplement it.

Create the project, i.e. a windows forms application
On the main window, place a label and a start button
Drop a timer object on the main window
Set the button properties (i.e. text)
Implement the onClick method for the button, write code for a counting variable which is set to a start value of timespan ( = 60 ) and add code for activation of of the timer object.
click the timer object below to view its properties and det them accordingly (i.e. the interval)
Doubleclick the timer object below the main window to create the onTick service method and fill it with the needed code (decrease value of the counter variable, display remaining value in the correct format, stop at the end, etc.)

Compile & test. Debug. Repeat as needed.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 40570648
Here's a quick example:
Public Class Form1

    Private TargetDateTime As DateTime
    Private WithEvents Tmr As New Timer

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Tmr.Interval = 1000
        Tmr.Enabled = False
        Label1.Text = "1:00:00"
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Button1.Enabled = False
        TargetDateTime = DateTime.Now.AddHours(1)
        Tmr.Start()
    End Sub

    Private Sub Tmr_Tick(sender As Object, e As EventArgs) Handles Tmr.Tick
        UpdateCountDown()
    End Sub

    Private Sub UpdateCountDown()
        Dim TS As TimeSpan = TargetDateTime.Subtract(DateTime.Now)
        If TS.TotalMilliseconds > 0 Then
            Label1.Text = TS.ToString("hh\:mm\:ss")
        Else
            Tmr.Stop()
            Label1.Text = "00:00:00"
            MessageBox.Show("Time's Up!")
            Button1.Enabled = True
        End If
    End Sub

End Class

Open in new window

0
 

Author Comment

by:Mike_Stevens
ID: 40570886
Frankhelk I can assure its not a homework assignment.
0
 

Author Comment

by:Mike_Stevens
ID: 40570901
Thanks Mike....exactly what I was looking for
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

805 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question