Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 7 Using Loops and Timers 199


as the time, use the System.DateTime.Now property instead of the TimeString property .)
Only one statement is required in this program because you set the Interval property for
the timer by using the Properties window. The timer object handles the rest.


  1. Click the Save All button on the Standard toolbar to save your changes. Specify
    C:\Vb10sbs\Chap07 as the folder location.


Tip The complete Digital Clock program is available in the C:\Vb10sbs\Chap07\Digital
Clock folder.


  1. Click the Start Debugging button on the Standard toolbar to run the clock.


The clock appears, as shown in the following screen shot. (Your time will be different, of
course .)

If you used the System.DateTime.Now property, you’ll also see the date in the clock,
as shown here:

I needed to enlarge the label object and the form a little here to get the date and time
to appear on one line. If your system clock information appears wrapped, close the
program and resize your label and form.


  1. Watch the clock for a few moments.


Visual Basic updates the time every second.


  1. Click the Close button in the title bar to stop the clock.


The Digital Clock program is so handy that you might want to compile it into an executable
file and use it now and then on your computer. Feel free to customize it by using your own
artwork, text, and colors.
Free download pdf