Visual Basic Express

Posted on 2008-11-09
Last Modified: 2013-11-27
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.
Question by:bosn1
    LVL 85

    Accepted Solution

    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
        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
                MessageBox.Show("Time's up!")
                Label1.Text = ts.Minutes & ":" & ts.Seconds.ToString.PadLeft(2, "0")
            End If
        End Sub
    End Class

    Open in new window


    Author Comment

    I was hoping to display a 30 minute count down, i.e.


    Author Comment

    I must have missed something the first time.  The soultion provided by Idle Mind is exactly what I need.

    Thank you
    LVL 32

    Expert Comment

    by:Daniel Wilson

    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?


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
    zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now