Visual Basic Express

I am looking for a way to add a count down clock to a form using Visual Basic Express.  I want to give the user a 30 minute warning before shutting down their computer.  I would like to have a count down beginning at 30:00.
bosn1Asked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
One way:
Public Class Form1
 
    Private targetDT As DateTime
    Private WithEvents tmr As New Timer
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        targetDT = DateTime.Now.AddMinutes(30)
        tmr.Interval = 1000
        tmr.Start()
    End Sub
 
    Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
        Dim ts As TimeSpan = targetDT.Subtract(DateTime.Now)
        If ts.TotalMilliseconds <= 0 Then
            tmr.Stop()
 
            MessageBox.Show("Time's up!")
 
        Else
            Label1.Text = ts.Minutes & ":" & ts.Seconds.ToString.PadLeft(2, "0")
        End If
    End Sub
 
End Class

Open in new window

0
 
bosn1Author Commented:
I was hoping to display a 30 minute count down, i.e.

30:00
29:59
29:58
0
 
bosn1Author Commented:
I must have missed something the first time.  The soultion provided by Idle Mind is exactly what I need.

Thank you
0
 
Daniel WilsonCommented:
Excellent!

I see you're relatively new to EE.  Welcome!

Since Idle_Mind's solution is what you needed, would you click the Accept link by his solution to close out the question and award him the points?

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.