Decision Making - PowerPoint PPT Presentation

1 / 46
About This Presentation
Title:

Decision Making

Description:

Open the Automobile Loan Calculator program you created in Chapter 4 ... for Auto Loan Calculator. 21. Chapter 5: Decision Making. The MessageBox Class ... – PowerPoint PPT presentation

Number of Views:248
Avg rating:3.0/5.0
Slides: 47
Provided by: ptcomp
Category:

less

Transcript and Presenter's Notes

Title: Decision Making


1
Chapter 5
  • Decision Making

2
Objectives
  • Use the ComboBox control
  • Use the IfThenElse structure
  • Use a nested IfThenElse structure
  • Use the Select Case structure
  • Validate user input

3
Objectives
  • Use the MessageBox class
  • Use the string concatenation in code
  • Use relational operators in code
  • Use logical operators in code

4
Modifying the Automobile Loan Calculator
Application
5
(No Transcript)
6
(No Transcript)
7
Opening the Project and Modifying the User
Interface
  • Open the Automobile Loan Calculator program you
    created in Chapter 4
  • Select the Form1 form in the main work area,
    right-click the form, and then click Lock
    Controls on the shortcut menu to unlock the form
  • Increase the form height to 248 pixels

8
Opening the Project and Modifying the User
Interface
  • Select the Label3 control, along with
    txtnMonthlyPament, btnComputePayment, and
    btnReset controls
  • Drag the controls down four marks on the
    positioning grid
  • Add a Label and ComboBox control from the Toolbox
    window and position as shown on the next slide

9
(No Transcript)
10
Label Control Properties
11
ComboBox Control Properties
12
ComboBox1 Control Properties
13
Setting the Items Property
  • Select the Items property in the Properties
    window
  • Click the Collection build button
  • Type the five items into the String Collection
    Editor, as shown on the following slide, and
    click the OK button
  • Upon completion, lock the controls using the
    Format menu

14
(No Transcript)
15
Modifying the Comment Header and Adding a Constant
16
Resetting the ComboBox Value
  • The SelectedIndex property of the ComboBox
    control is assigned the value of the items index
  • When no item is selected, the SelectedIndex
    property is set to -1
  • Add the following line of code to the end of the
    btnReset_Click Event Procedure

17
Declaring Additional Variables
  • Two additional variables are needed in the
    btnComputePayment_Click event procedure
  • Scroll the code window until line 258 appears
  • Enter line 259 as shown below

18
Decision-Making Control Structures
  • Decision making is the process of determining
    which of one or more paths to take
  • IfThenElse structure
  • Select Case structure

19
IfThenElse Structure
Select Case Structure
20
IfThenElse Structure for Auto Loan Calculator
21
The MessageBox Class and the Show() Method
  • The MessageBox class provides the ability to
    display a message to the user in a pop-up window
  • The Show() method must be used to display a
    message with a title bar
  • MessageBox.Show(Please enter the customers
    credit rating in the Credit rating list box.,No
    Credit Rating)

22
The Focus() Method
  • When a user selects a control on a form, the
    control is said to have focus
  • It is often necessary to set the focus to a
    control during run time
  • cmbCreditRating.Focus()

23
IfThenElse Statement
  • Relational expression
  • , lt, gt, lt, gt, ltgt
  • Single-line IfThenElse statement
  • Block IfThenElse statement
  • Block-level scoping
  • Exit Sub Statement
  • Terminates execution of a procedure immediately

24
IfThenElse Structure
  • Enter the following code, starting on line 263
  • Parameter Info window

25
Considering Selection Structures
26
The Nested IfThenElse Structure
27
Coding a Nested IfThenElse Structure
28
Coding a Nested IfThenElse Structure
  • In the code window, delete lines 240 through 251
  • Starting on line 259, enter the following code

29
Logical Operators
  • The Not Logical Operator
  • The And Logical Operator
  • The Or Logical Operator
  • The Xor Logical Operator
  • Other Logical Operators
  • AndAlso
  • OrElse

30
Combining Logical Operators
  • If XgtY Or TD And Hlt3 Or Not YR Then
  • intCount intCount 1
  • End If
  • Rules of precedence
  • Arithmetic operators
  • Relational operators
  • Not operators
  • And/AndAlso operators
  • Or/OrElse or Xor operators

31
The Effect of Parentheses in the Evaluation of
Compound Conditions
  • Parentheses can be used to change the order of
    precedence
  • Avoid ambiguity and group conditions with a
    desired logical operator
  • (CgtD And S4) Or (XltY And T5)

32
Coding with a Logical Operator and String
Expressions
33
Coding with a Logical Operator and String
Expressions
  • Concatenation () operator
  • strErrorMessage Customers with this credit
    rating may only borrow strMoney
  • The plus sign () can be used instead of the ()
    operator

34
Coding with a Logical Operator and String
Expressions
  • Enter the following code, starting on line 272

35
The Select Case Structure
  • Used to implement an extension of the
    IfThenElse structure

36
(No Transcript)
37
Coding a Select Case Statement
38
Coding a Select Case Statement
  • Enter the following code, starting on line 284

39
Modifying a Parameter in a Function Call
  • The function call to the Pmt function currently
    accepts the dblRate variable as the interest rate
    parameter
  • This does not take into account the customers
    credit rating
  • In line 300, click between the letters l and R in
    the dblRate parameter in the Pmt function call
    and enter Adjusted to change the parameter name

40
(No Transcript)
41
Saving and Testing the Project
  • Click the Save All button on the Standard toolbar
  • Click the Start button on the Visual Basic .NET
    Standard toolbar
  • Enter 13000 for the Loan amount. Enter 10.25 for
    the Current interest rate in the second
    NumericUpDown control. Click the Compute Payment
    button
  • The No Credit Rating message box should display

42
Saving and Testing the Project
  • Click the OK button. Click the Credity rating
    box arrow and then select B Good in the Credit
    rating drop-down list. Click the Compute Payment
    button
  • The resulting output should display 284.44
  • Click the Close button on the Automobile Loan
    Calculator application window title bar

43
Document the Application and Quit Visual Basic
.NET
  • Prepare printouts of your project, as
    demonstrated in Chapter 2
  • Click the Visual Basic .NET Close button

44
Summary
  • Use the ComboBox control
  • Use the IfThenElse structure
  • Use a nested IfThenElse structure
  • Use the Select Case structure
  • Validate user input

45
Summary
  • Use the MessageBox class
  • Use the string concatenation in code
  • Use relational operators in code
  • Use logical operators in code

46
Chapter 5 Complete
Write a Comment
User Comments (0)
About PowerShow.com