Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.

Slides:



Advertisements
Similar presentations
Working with Intrinsic Controls and ActiveX Controls
Advertisements

Programming with Microsoft Visual Basic th Edition
1.
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel Project 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Using Macros and Visual Basic for Applications (VBA) with Excel
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Programming with Microsoft Visual Basic th Edition
Using the Visual Basic Editor Visual Basic for Applications 1.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
CHAPTER SIX Loop Structures.
Microsoft Visual Basic 2005 CHAPTER 12 Cell Phone Applications and Web Services.
CHAPTER 6 Loop Structures.
Microsoft Visual Basic 2012 CHAPTER TWELVE (ENRICHMENT CHAPTER) Windows Store Apps.
Visual Basic Chapter 1 Mr. Wangler.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Chapter Four The Selection Structure
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
Microsoft Visual Basic 2005 CHAPTER 5 Mobile Applications Using Decision Structures.
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Chapter 4: The Selection Structure
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Chapter 4: The Selection Process in Visual Basic.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 2 The Visual Basic.NET Integrated Development Environment.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Seven More on the Repetition Structure.
Chapter 4: The Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 4: The Selection Structure
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 8 Dental Payment Application Introducing CheckBox es and Message Dialogs.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
OCC Network Drives  H:\  P:\ 
Microsoft Visual Basic 2008 CHAPTER TWELVE Cell Phone Applications and Web Services.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Access Project 7 Advanced Report and Form Techniques.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
1.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Visual Basic.NET Programming for the Rest of Us Keith Mulbery Utah Valley State College.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 2 The Visual Basic.NET Integrated Development Environment.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 12 Creating Console Applications, Understanding XML, and Creating Web Services.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
Visual Basic.NET Windows Programming
CHAPTER FIVE Decision Structures.
Chapter 4: The Selection Structure
Using Procedures and Exception Handling
VISUAL BASIC FINAL EXAM REVIEW SHEET
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
CHAPTER FIVE Decision Structures.
Variables and Arithmetic Operations
Microsoft Visual Basic 2005: Reloaded Second Edition
VB.NET PROGRAMMING FINAL EXAM TEST REVIEW.
Microsoft Visual Basic 2005: Reloaded Second Edition
Presentation transcript:

Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making

Chapter 5: Decision Making 2 Objectives Use the ComboBox control Use the If…Then…Else structure Use a nested If…Then…Else structure Use the Select Case structure Validate user input

Chapter 5: Decision Making 3 Objectives Use the MessageBox class Use the string concatenation in code Use relational operators in code Use logical operators in code

Chapter 5: Decision Making 4 Modifying the Automobile Loan Calculator Application

Chapter 5: Decision Making 5

6

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

Chapter 5: Decision Making 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

Chapter 5: Decision Making 9

10 Label Control Properties

Chapter 5: Decision Making 11 ComboBox Control Properties

Chapter 5: Decision Making 12 ComboBox1 Control Properties

Chapter 5: Decision Making 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

Chapter 5: Decision Making 14

Chapter 5: Decision Making 15 Modifying the Comment Header and Adding a Constant

Chapter 5: Decision Making 16 Resetting the ComboBox Value The SelectedIndex property of the ComboBox control is assigned the value of the item’s 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:

Chapter 5: Decision Making 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:

Chapter 5: Decision Making 18 Decision-Making Control Structures Decision making is the process of determining which of one or more paths to take –If…Then…Else structure –Select Case structure

Chapter 5: Decision Making 19 If…Then…Else Structure Select Case Structure

Chapter 5: Decision Making 20 If…Then…Else Structure for Auto Loan Calculator

Chapter 5: Decision Making 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 customer’s credit rating in the Credit rating list box.”,”No Credit Rating”)

Chapter 5: Decision Making 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()

Chapter 5: Decision Making 23 If…Then…Else Statement Relational expression =,, =, <> Single-line If…Then…Else statement Block If…Then…Else statement Block-level scoping Exit Sub Statement –Terminates execution of a procedure immediately

Chapter 5: Decision Making 24 If…Then…Else Structure Enter the following code, starting on line 263: Parameter Info window

Chapter 5: Decision Making 25 Considering Selection Structures

Chapter 5: Decision Making 26 The Nested If…Then…Else Structure

Chapter 5: Decision Making 27 Coding a Nested If…Then…Else Structure

Chapter 5: Decision Making 28 Coding a Nested If…Then…Else Structure In the code window, delete lines 240 through 251 Starting on line 259, enter the following code

Chapter 5: Decision Making 29 Logical Operators The Not Logical Operator The And Logical Operator The Or Logical Operator The Xor Logical Operator Other Logical Operators –AndAlso –OrElse

Chapter 5: Decision Making 30 Combining Logical Operators If X>Y Or T=D And H<3 Or Not Y=R Then intCount = intCount + 1 End If Rules of precedence –Arithmetic operators –Relational operators –Not operators –And/AndAlso operators –Or/OrElse or Xor operators

Chapter 5: Decision Making 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 (C>D And S=4) Or (X<Y And T=5)

Chapter 5: Decision Making 32 Coding with a Logical Operator and String Expressions

Chapter 5: Decision Making 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

Chapter 5: Decision Making 34 Coding with a Logical Operator and String Expressions Enter the following code, starting on line 272

Chapter 5: Decision Making 35 The Select Case Structure Used to implement an extension of the If…Then…Else structure

Chapter 5: Decision Making 36

Chapter 5: Decision Making 37 Coding a Select Case Statement

Chapter 5: Decision Making 38 Coding a Select Case Statement Enter the following code, starting on line 284

Chapter 5: Decision Making 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 customer’s 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

Chapter 5: Decision Making 40

Chapter 5: Decision Making 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 for the Loan amount. Enter for the Current interest rate in the second NumericUpDown control. Click the Compute Payment button –The No Credit Rating message box should display

Chapter 5: Decision Making 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 $ Click the Close button on the Automobile Loan Calculator application window title bar

Chapter 5: Decision Making 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

Chapter 5: Decision Making 44 Summary Use the ComboBox control Use the If…Then…Else structure Use a nested If…Then…Else structure Use the Select Case structure Validate user input

Chapter 5: Decision Making 45 Summary Use the MessageBox class Use the string concatenation in code Use relational operators in code Use logical operators in code

Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Complete