Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

104 Part I Getting Started with Microsoft Visual Basic 2010


MenuStrip control is related to the ToolStrip control. (We’ll see further examples of that
later in this chapter .) The _Click syntax means that this is the event procedure that runs
when a user clicks the menu item.
We’ll keep this menu name for now, but if you wanted to create your own internal
names for menu objects, you could select the object, open the Properties window,
and change the Name property. Although I won’t bother with that extra step in this
chapter, later in the book you’ll practice renaming objects in your program to conform
more readily to professional programming practices.


  1. Type the following program statement:


Label1.Text = TimeString
This program statement displays the current time (from the system clock) in the Text
property of the Label1 object, replacing the previous Label1 text (if any). TimeString
is a property that contains the current time formatted for display or printing. You can
use TimeString at any time in your programs to display the time accurately down to
the second. (TimeString is essentially a replacement for the older Microsoft Visual Basic
TIME$ statement .)

Note The Visual Basic TimeString property returns the current system time. You can set
the system time by using the Clock, Language, and Region category in the Control Panel
in Windows Vista or Windows 7.


  1. Press ENTER.


Visual Basic interprets the line and adjusts capitalization and spacing, if necessary.
(Visual Basic checks each line for syntax errors as you enter it .)

Tip You can enter a line by pressing ENTER or ESC. You can also press the UP ARROW or
DOWN ARROW key to enter a line if you don’t want the extra blank space (carriage return)
in the Code Editor.


  1. Click the View Designer button in Solution Explorer, and then double-click the Date
    command on the Clock menu.
    The DateToolStripMenuItem_Click event procedure appears in the Code Editor.
    This event procedure is executed when the user clicks the Date command on the
    Clock menu.

  2. Type the following program statement:


Label1.Text = DateString
Free download pdf