Chapter 7: Using Loops and Timers


Chapter 7

Using Loops and Timers

After completing this chapter, you will be able to:

  • Use a For…Next loop to execute statements a set number of times.

  • Display output in a multiline text box by using string concatenation.

  • Use a Do loop to execute statements until a specific condition is met.

  • Use the Timer control to execute code at specific times.

  • Create your own digital clock and timed password utility.

  • Use the new Insert Snippet command to insert ready-made code templates or snippets into the Code Editor.

In Chapter 6, “Using Decision Structures,” you learned how to use the If…Then and Select Case decision structures to choose which statements to execute in a program. You also learned how to process user input and evaluate different conditions in a program, and how to determine which block of program statements to execute based on changing conditions. Now you'll continue learning about program execution and flow control by using loops to execute a block of statements over and over again. You'll also create a digital clock and other interesting utilities that perform actions at set times or in relation to intervals on your computer's system clock.

In this chapter, you'll use a For…Next loop to execute statements a set number of times, and you'll use a Do loop to execute statements until a conditional expression is met. You'll also learn how to display more than one line of text in a text box object by using the string concatenation (&) operator, and you'll learn how to use the Visual Studio Timer control to execute code at specific intervals in your program. Finally, you'll learn how to use the Insert Snippet command to insert code templates into your programs—a handy new feature of the Microsoft Visual Studio 2005 IDE.

Upgrade Notes: Migrating Visual Basic 6 Code to Visual Basic 2005

If you're experienced with Microsoft Visual Basic 6, you'll notice some new features in Visual Basic 2005, including the following:

  • In Visual Basic 6, you can display text directly on your form by using the Print method, a holdover from the Print statement in GW-BASIC and Microsoft QuickBasic. In Visual Basic 2005, the Print method can be used only to send data to a file on disk. This chapter shows you an alternative method for displaying large amounts of text on a form—appending text in a multiline text box object by using the string concatenation operator (&).

  • In Visual Basic 6, a While loop is specified with the While…Wend syntax. In Visual Basic 2005, the closing statement is While…End While to parallel other similar structures.

  • The Timer control in Visual Studio 2005 is similar but not identical to the Timer control in Visual Basic 6. For example, the Timer1_Timer event procedure (which is executed at each pre-set timer interval) is called Timer1_Tick in Visual Studio 2005. In addition, you can no longer disable a timer by setting the Interval property to 0.



Microsoft Visual Basic 2005 Step by Step
Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))
ISBN: B003E7EV06
EAN: N/A
Year: 2003
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net