Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 7 Using Loops and Timers 203



  1. Run the program again, type secret (the correct password) in the text box, and then
    click Try Password.
    The program displays this message:

  2. Click OK to end the program.


The Visual Basic development environment appears.
As you can imagine, there are many practical uses for timer objects. As with For... Next
loops and Do loops, you can use timer objects to repeat commands and procedures as many
times as you need in a program. Combined with what you learned about the If... Then and
Select Case decision structures in Chapter 6, you now have several statements, controls,
and techniques that can help you organize your programs and make them respond to
user input and data processing tasks in innovative ways. Learning to pick the best tool for
the flow-control situation at hand takes some practice, of course, but you’ll have ample
opportunity to try these tools and techniques as you continue working in the upcoming
chapters, and as you construct interesting applications on your own. In fact, you might
take the opportunity right now to create a simple project or two from scratch before you
tackle the next chapter, which discusses debugging. How about creating a digital clock that
displays a different piece of art in a picture box object every 30 seconds?

One Step Further: Inserting Code Snippets


If you enjoyed using the system clock and other Windows resources in this chapter, you
might appreciate one additional example that uses the Computer.Info object to display useful
information about the operating system you’re currently using. This example also demonstrates
an interesting feature of Visual Studio called the Insert Snippet command, which lets you
insert ready-made code templates or snippets into the Code Editor from a list of common
programming tasks. Visual Studio comes automatically configured with a library of useful
code snippets, and you can add additional snippets from your own programs or from online
resources such as MSDN. The following exercise shows you how to use this helpful feature.

Insert the Current Windows Version Snippet


  1. On the File menu, click the New Project command, and create a new Windows Forms
    Application project named My Windows Version Snippet.
    The new project is created, and a blank form opens in the Designer.

Free download pdf