Professional Documents
Culture Documents
Reloaded
Fourth Edition
Chapter Six
Repeating Program Instructions
Objectives
Figure 6-2: Problem specification for the Getting to a Million Club application
Figure 6-7: Flowchart for the pretest loop example from Figure 6-6
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 13
The Do...Loop Statement (cont'd.)
Figure 6-8: Flowchart for the posttest loop example from Figure 6-6
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 14
Using Counters and Accumulators
Figure 6-9: Modified pseudocode and code for the calcButton’s Click event
procedure (cont’d.)
Figure 6-10: Sample run of the modified Getting to a Million Club application
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 17
The Sales Express Company
Application
• Requirements: display the average amount the
company sold during the prior year
• Input: the amount of each salesperson’s sales
• Multiline property: if True, allows multiple lines
of text in a text box
• ReadOnly property: if True, prevents a user from
changing the text box contents during run time
• ScrollBars property: specifies whether a text
box has no scroll bars, horizontal or vertical, or
both
Figure 6-13: Pseudocode for the Average button’s Click event procedure
Figure 6-17: Code associated with the pseudocode and flowchart shown in
Figures 6-13 and 6-14, respectively (cont’d.)
Figure 6-20: Add methods entered in the MainForm’s Load event procedure
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 35
Adding Items to a List Box (cont'd.)
Figure 6-23: Add to List button’s Click event procedure in the Jasper’s
Food Hut application
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 37
Adding Items to a List Box (cont'd.)
Figure 6-25: Add to List button’s Click event procedure in the Clark’s
Chicken application
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 38
Adding Items to a List Box (cont'd.)
• Sorted property:
– Determines if the list box items are sorted
– Sort order is dictionary order
• Index:
– A unique number that identifies an item in a
collection
– Is zero-relative: the first item has index of 0
• SelectedValueChanged and
SelectedIndexChanged events:
– Occur when a user selects an item in a list box
– Occur when a code statement selects an item in a list
box
Figure 6-35: Sample run of the application when the product ID is not found
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 54
The Product Finder Application
(cont'd.)
Figure 6-36: Pseudocode for the Find button’s Click event procedure