• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

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.
0
bosn1
Asked:
bosn1
  • 2
1 Solution
 
Mike TomlinsonMiddle 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

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now