Start your copy of Microsoft Visual Basic Express. From the main window, click on "New Project." Once the new project window is open, select "Windows Forms Application." Finish by clicking "OK."
Add a button to the project window by double clicking the "Button" tool from the "Toolbox" palette. This will start the countdown. Add a "Timer" and "Label" the same way as the button. The timer will act as the control for the countdown and the label will act as the display.
Select the button you just added to the project window. It will be named "Button1." Double click this button to open the "Form1.vb" module. Locate the input under the "Button1_Click." You will now add the code that will set the timer interval to 1 second counting down from 15 minutes. Enter the following code then click "OK":
Timer1.Interval = 1000
Timer1.Start()
cntDown = Date.Now.AddMinutes(15)
Find and select the "Form1.vb [Design]" tab from the project window. Find the "Timer" control on the project window and double click.
Locate the input field under the "Timer1_Tick." The following code will now add the commands that will check the progression of the countdown and reflect its progress in the label display. Input the following codes and finish by clicking "OK":
If cntDown < Date.Now Then
Me.Timer1.Stop()
MessageBox.Show("Countdown has completed!")
Else
Dim timeRem As TimeSpan = Me.cntDown.Subtract(Date.Now)
Me.Label1.Text = String.Format("{0}:{1:d2}:{2:d2}", _
timeRem.Hours, _
timeRem.Minutes, _
timeRem.Seconds)
End If
Save the project. Click on "File" then select "Save" from the menu bar. With the project still open, click "F5" to activate the codes and make the countdown timer live. Test by clicking "Button1." The timer display will now count down from 15 minutes.
0 comments:
Post a Comment
Click to see the code!
To insert emoticon you must added at least one space before the code.