ppt lesson 11
TRANSCRIPT
Microsoft Visual Basic 2005 BASICS
Lesson 11
List Boxes, For Next Loops, and Label Settings
Microsoft Visual Basic 2005 BASICS 2
Objectives
Use the ListBox control to show multiple lines of information.
Use For Next loops. Nest For Next loops. Change label font settings.
Microsoft Visual Basic 2005 BASICS 3
Using the ListBox Control
ListBox control Enables you to display a list of items to the
user Add information to a ListBox
Use the Items.Add method Remove all items added to a ListBox
Use the Items.Clear method
Microsoft Visual Basic 2005 BASICS 4
Using the ListBox Control (cont.)
Microsoft Visual Basic 2005 BASICS 5
Using For Next Loops
For Next loop Specifically designed for repeating a block
of code a specific number of times Always begins with a For statement and
ends with a Next statement Always involves a Counter variable
Microsoft Visual Basic 2005 BASICS 6
Using For Next Loops (cont.)
Microsoft Visual Basic 2005 BASICS 7
Using the Step Keyword to Count Forward
Step keyword Used to cause the loop counter to count by
an increment other than one
Microsoft Visual Basic 2005 BASICS 8
Using the Step Keyword to Count Backward
Use a negative value After the Step keyword to count backward
Microsoft Visual Basic 2005 BASICS 9
Nesting For Next Loops
For Next loops can be nested Within other For Next loops or within Do loops
When you nest For Next loops Each nested loop must be completely
contained within the outer loop
Microsoft Visual Basic 2005 BASICS 10
Nesting For Next Loops (cont.)
Microsoft Visual Basic 2005 BASICS 11
Changing Label Font Settings
Control the font, style, and size Using the Font property of the label control
You can make labels appear in any font installed on your computer.
Microsoft Visual Basic 2005 BASICS 12
Changing Label Font Settings (cont.)
Microsoft Visual Basic 2005 BASICS 13
Changing Label Font Settings (cont.)
Microsoft Visual Basic 2005 BASICS 14
Summary
Visual Basic 2005 includes a ListBox control for displaying lists of information. The Items.Add method adds items to a ListBox control. The Items.Clear method removes all entries in a ListBox control.
A For Next loop is specifically designed for repeating a block of code a specific number of times.
Microsoft Visual Basic 2005 BASICS 15
Summary (cont.)
A For Next loop always begins with a For statement and ends with a Next statement. The statements between the For and Next statements are repeated the number of times specified in the For Next loop.
For Next loops always involve a Counter variable.
Microsoft Visual Basic 2005 BASICS 16
Summary (cont.)
If you want a For Next loop to count by an increment other than 1, you can use the Step keyword. The Step keyword can also be used to make a For Next loop count backward.
For Next loops can be nested.
Microsoft Visual Basic 2005 BASICS 17
Summary (cont.)
Indenting your code can help make nested For Next loops easier to read. You can also use Next statements that specify the counter variable of the loop.
You can use the Font property to change the font, style, and size of a label.