Microsoft Visual Basic 2010: Reloaded Fourth Edition - PowerPoint PPT Presentation

Loading...

PPT – Microsoft Visual Basic 2010: Reloaded Fourth Edition PowerPoint presentation | free to download - id: 4434b2-YWQzO



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Microsoft Visual Basic 2010: Reloaded Fourth Edition

Description:

... a periodic payment using the Financial.Pmt method Select the existing text in a text box Code the TextChanged event procedure for a text box Microsoft Visual ... – PowerPoint PPT presentation

Number of Views:84
Avg rating:3.0/5.0
Slides: 56
Provided by: course1Wi5
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Microsoft Visual Basic 2010: Reloaded Fourth Edition


1
Microsoft Visual Basic 2010 Reloaded Fourth
Edition
  • Chapter Seven
  • More on the Repetition Structure

2
Objectives
  • After studying this chapter, you should be able
    to
  • Code a counter-controlled loop using the ForNext
    statement
  • Nest repetition structures
  • Calculate a periodic payment using the
    Financial.Pmt method
  • Select the existing text in a text box
  • Code the TextChanged event procedure for a text
    box

2
3
Objectives (cont'd.)
  • Code a list boxs SelectedValueChanged and
    SelectedIndexChanged event procedures
  • Include a combo box in an interface
  • Code the TextChanged event procedure for a combo
    box
  • Store images in an image list control
  • Display an image stored in an image list control

3
4
The For...Next Statement
  • For...Next statement processes a set of
    instructions a known number of times
  • Is a pretest loop
  • Counter-controlled loop a loop whose processing
    is controlled by a counter
  • Counter variable used to keep track of the
    number of times the loop has been processed
  • Startvalue, endvalue, and stepvalue items
  • Control the number of times the loop is processed
  • Must evaluate to numeric values
  • Can be positive or negative

4
5
The For...Next Statement (cont'd.)
  • A negative stepvalue causes the loop counter to
    count down
  • Decrementing adding increments of a negative
    number
  • Flowchart symbol for the For...Next loop is a
    hexagon
  • Values for the counter variable, startvalue,
    stepvalue, and endvalue are shown within the
    hexagon

5
6
Figure 7-1 How to use the ForNext statement
6
7
Figure 7-1 How to use the ForNext statement
(contd.)
7
8
The For...Next Statement (cont'd.)
Figure 7-2 Processing steps for Example 1 in
Figure 7-1
8
9
The For...Next Statement (cont'd.)
Figure 7-2 Processing steps for Example 1 in
Figure 7-1 (contd.)
9
10
The For...Next Statement (cont'd.)
Figure 7-3 Problem specification for the Savings
Account application
10
11
The For...Next Statement (cont'd.)
Figure 7-4 Sample run of the Savings Account
application
11
12
Figure 7-5 Pseudocode and flowchart for the
Calculate buttons Click event procedure
12
13
The For...Next Statement (cont'd.)
Figure 7-6 Calculate buttons Click event
procedure
13
14
The For...Next Statement (cont'd.)
  • Can use ForNext or DoLoop for a
    counter-controlled loop
  • With DoLoop, you must
  • Declare and initialize the counter variable
  • Update the counter variable
  • Include an appropriate comparison in the Do
    clause
  • ForNext statement handles the declaration,
    initialization, update, and comparison tasks
  • Is more convenient to use

15
The For...Next Statement (cont'd.)
Figure 7-7 Comparison of the ForNext and
DoLoop statements
15
16
Nested Repetition Structures
  • Repetition structures can be nested
  • Can use pretest or posttest loops for outer loop
    and for inner (nested) loop
  • A clock with minute and second hands demonstrates
    nested loops
  • Minute hand moves 1 position, then the second
    hand moves 60 positions

17
Figure 7-8 Three versions of the logic used by a
clocks minute and second hands
18
Nested Repetition Structures (contd.)
Figure 7-9 Modified problem specification for
the Savings Account application
Figure 7-9 Sample run of the Savings Account
application
19
Nested Repetition Structures (contd.)
Figure 7-11 Two versions of the Calculate
buttons Click event procedure
20
Figure 7-11 Two versions of the Calculate
buttons Click event procedure (contd.)
21
The Payment Calculator Application
Figure 7-12 Problem specification for the
Payment Calculator application
22
The Payment Calculator Application (contd.)
Figure 7-13 Sample run of the Payment Calculator
application
23
The Financial.Pmt Method
  • Financial.Pmt method
  • Calculates a periodic payment on a loan or
    investment
  • Returns the periodic payment as a Double type
    value
  • Rate and number of periods arguments must be
    expressed in the same units (monthly, annual,
    etc.)

23
24
Figure 7-14 How to use the Financial.Pmt method
24
25
The Financial.Pmt Method (contd.)
Figure 7-15 Pseudocode and code for the
Calculate buttons Click event procedure
26
Figure 7-15 Pseudocode and code for the
Calculate buttons Click event procedure
27
Selecting the Existing Text in a Text Box
  • SelectAll method selects all text in a text box
    for replacement typing
  • User only needs to type the new value
  • Enter event occurs when the text box receives
    the focus
  • When the user tabs to the control
  • When the user uses the controls access key
  • When the Focus method sends the focus to the
    control
  • When the user clicks in the text box

27
28
Selecting the Existing Text in a Text Box
(cont'd.)
Figure 7-16 How to use the SelectAll method
28
29
Selecting the Existing Text in a Text Box
(cont'd.)
Figure 7-17 Loan text boxs Enter event procedure
29
30
Selecting the Existing Text in a Text Box
(cont'd.)
Figure 7-18 Result of processing the text boxs
Enter event procedure
30
31
Selecting the Existing Text in a Text Box
(cont'd.)
  • Entering a new value in the Loan text box does
    not update the monthly payments until the user
    clicks the Calculate button
  • May cause confusion

Figure 7-19 New loan amount entered in the Loan
text box
31
32
Coding the TextChanged Event Procedure
  • TextChanged event
  • Occurs when a change is made in a controls Text
    property
  • Change may be made by user or the program

Figure 7-20 New principal entered in the
Principal text box
32
33
Coding the TextChanged Event Procedure (contd.)
Figure 7-21 Result of processing the text boxs
TextChanged event procedure
33
34
Coding the SelectedValueChanged and
SelectedIndexChanged Event Procedures
Figure 7-22 The list boxs SelectedValueChanged
and SelectedIndexChanged event procedures
34
35
Including a Combo Box in an Interface
  • Combo Box control
  • Similar to a list box with a list of choices
  • List portion may be hidden
  • May contain a text field that allows the user to
    type an entry that is not on the list
  • Three styles of combo boxes, controlled by the
    DropDownStyle property
  • Simple
  • DropDown (the default)
  • DropDownList

35
36
Using a Combo Box in an Interface
Figure 7-23 Examples of the three styles of
combo boxes
36
37
Figure 7-24 Code used to fill the combo boxes in
Figure 7-23 with values
37
38
Using a Combo Box in an Interface (cont'd.)
  • Items.Add method used to add items to a combo
    box
  • SelectedItem property contains the value of the
    selected item in the list
  • Text property contains the value that appears in
    the text portion of the control (item selected or
    typed in)
  • Items.count property used to obtain the number
    of items in the combo box
  • Sorted property used to sort the items in the
    list

38
39
Using a Combo Box in an Interface (cont'd.)
Figure 7-25 Sample run of the Payment Calculator
application using a combo box
39
40
Figure 7-26 Code for the Payment Calculator
application shown in Figure 7-25
40
41
Figure 7-26 Code for the Payment Calculator
application shown in Figure 7-25 (contd.)
41
42
Using an Image List Control
  • Image List control
  • Stores a collection of images
  • Does not appear on the form appears in the
    component tray
  • Add images to the control using the Images
    Collection Editor window

43
Using an Image List Control (contd.)
Figure 7-27 Image Viewer application
44
Using an Image List Control (contd.)
Figure 7-28 How to add images to an image list
controls Images collection
45
Using an Image List Control (contd.)
Figure 7-29 Completed Images Collection Editor
window in the Image Viewer application
46
Using an Image List Control (contd.)
Figure 7-30 How to refer to an image in the
Images collection
47
Using an Image List Control (contd.)
Figure 7-31 Sample run of the Image Viewer
application
48
Using an Image List Control (contd.)
Figure 7-32 Code entered in the View buttons
Click event procedure
49
Programming Tutorial 1
  • Creating the Slot Machine Application

Figure 7-34 MainForm in the Slot Machine
application
49
50
Programming Tutorial 2
  • Creating the Birmingham Sales Application

Figure 7-40 MainForm for the Birmingham Sales
application
50
51
Programming Example
  • Raise Calculator Application

Figure 7-46 MainForm for the Raise Calculator
application
51
52
Summary
  • For...Next statement a pretest loop that will
    process the instructions a fixed number of times
  • A variable declared in a For clause has block
    scope
  • Use a hexagon in a flowchart for a ForNext loop
  • Financial.Pmt method calculates a periodic
    payment on a loan or investment
  • SelectAll method highlights text in a text box
  • TextChanged event occurs when a controls text
    changes

52
53
Summary (cont'd.)
  • Combo box similar to a list box but may not
    expose the list items until clicked
  • Three styles of combo boxes Simple, DropDown,
    and DropDownList
  • Combo boxs Items.Add method adds an item to the
    list
  • Use SelectedItem, SelectedIndex, or Text property
    of a combo box to set the default item in a combo
  • Combo boxs Items.Count property used to obtain
    the number of items listed in the combo box

53
54
Summary (cont'd.)
  • Combo boxs Sorted property used to sort items
    listed in a combo box
  • Combo boxs SelectedItem property contains the
    value of the item selected in the list portion of
    the combo box
  • Combo boxs Text property contains the value
    that appears in the text portion of the combo box
  • Combo boxs TextChanged event occurs when the
    user either selects an item in the list portion
    or types a value in the text portion

54
55
Summary (cont'd.)
  • Image list control stores a set of images in its
    Images collection
  • Images in an image list control belong to the
    Images collection
  • Access an image in the Images collection using
    the Item property with the index of the desired
    image
  • Image collections Count property contains the
    number of images in the collection
  • Use a picture box control to display an image
    contained in an image list control

55
About PowerShow.com