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

Slides:



Advertisements
Similar presentations
Lists, Loops, Validation, and More
Advertisements

CS0004: Introduction to Programming Select Case Statements and Selection Input.
Working with Intrinsic Controls and ActiveX Controls
Programming with Microsoft Visual Basic th Edition
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
1.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
C++ for Engineers and Scientists Third Edition
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Visual Basic Chapter 1 Mr. Wangler.
Microsoft Visual Basic 2005 CHAPTER 5 Mobile Applications Using Decision Structures.
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Chapter 4: The Selection Structure
Chapter 4 The If…Then Statement
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
VB.NET PROGRAMMING FINAL EXAM TEST REVIEW.
Chapter 4: The Selection Process in Visual Basic.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
Lecture Set 5 Control Structures Part A - Decisions Structures.
5-1 Chapter 5 The Repetition Process in VB.NET. 5-2 Learning Objectives Understand the importance of the repetition process in programming. Describe the.
1 Boolean Expressions to Make Comparisons Boolean expression –Represents only one of two states –Expression evaluates to either true or false Expressions.
COMPUTER PROGRAMMING II SUMMER 2011 Visual Basic to C#
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
JavaScript, Fourth Edition
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
110 F-1 Decisions and Conditions Chapter 4: We can design a form We can calculate To make our programs more powerful, we need to be able to make choices.
Unit 6 Repetition Processing Instructor: Brent Presley.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code (loop body) that may be executed several times. Fixed-count (definite) loops repeat.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Making Interactive Programs with Visual Basic .NET
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Visual Basic/ Visual Studio Brandon Large. Connecting to prior knowledge In your notes write down what the two main parts of the computer are. The “software”
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Visual Basic.NET Windows Programming
Chapter 4 The If…Then Statement
2.5 Another Java Application: Adding Integers
CHAPTER FIVE Decision Structures.
VISUAL BASIC FINAL EXAM REVIEW SHEET
Microsoft Visual Basic 2005 BASICS
CHAPTER FIVE Decision Structures.
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 3: Introduction to Problem Solving and Control Statements
Items, Group Boxes, Check Boxes & Radio Buttons
CIS 16 Application Development Programming with Visual Basic
VB.NET PROGRAMMING FINAL EXAM TEST REVIEW.
Introduction to Problem Solving and Control Statements
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Chapter 3: Selection Structures: Making Decisions
Presentation transcript:

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

2 Modifying the Automobile Loan Calculator Application

3

4 New Control – ComboBox ComboBox control – used in Windows applications to present lists of choices. Uses the prefix cmb. DropDownStyle Property – used to change the appearance of the list and the method used to select an item. –Simple: List always displays; scroll bar added if list is longer than the ComboBox height. –DropDown: List drops down when you click on the box. You can type directly into the box. (Default) –DropDownList: List drops down when you click on the box; you CANNOT type directly into the box. Items Property – used to build the list!

5 Adding Items to the ComboBox During Design Time

6 Understanding ComboBox Indexes When you add items to a ComboBox List VB.Net assigns each one an unique index number. The first item is assigned an index of 0; the second item gets an index of 1; and so on. –For example: Index Numbers for Auto Loan Program A -- Excellent Credit Rating = 0 B – Good Credit Rating = 1 etc …. SelectedIndex is the property that keeps track of what index number is currently being accessed. When no item is selected, the SelectedIndex property is set to -1. The following line of code would clear the ComboBox:

7 Decision-Making Control Structures In previous chapters, the programs were designed to perform precisely the same computations for every set of data items that were processed. In some instances, you want it to do the calculation different ways under different circumstances. –For example: The Auto Loan Program uses higher interest rates for those deemed to be “higher risk” loans. –In order to do this the program must be coded to make a decision concerning which interest rate to use! Decision-making is the process of determining which of one or more paths to take. We will learn two new code structures to help you begin this process! –If…Then…Else structure –Select Case structure

8 If…Then…Else Structure Select Case Structure

9 If…Then…Else Structure for Auto Loan Calculator

10 IF … THEN … ELSE STATEMENTS If…Then…Else statements are used to execute one statement or another conditionally. –The condition follows the keyword IF –A condition is made up of two expressions and a relational (comparison) operator. Equal =Less than or equal to <= Less than = Greater than > Not equal to <> Nested If.. Then … Else Structure: when you have an if…then within an if then!

11 MORE ABOUT IF.. THEN.. ELSE The statement to be executed if the condition is true follows the keyword then. The statement to be executed if the condition is false follows the keyword else. For Example: If dblSales > 500 then dblBonus = 100 Else dblBonus = 0 End if If a variable is declared within a block if..then, it will only work in that block. That is referred to as block-level scoping.

12 Another Example of If … Then As we mentioned earlier … you can have a nested if … then structure: which is an if then within another if … then. For example: If radTwoYears.Checked = True Then gdblMonths = 24 Else If radFiveYears.Checked = True Then gdblMonths = 60 Else gdblMonths = 72 End if Note: Every If needs an End if!

13 Select Case Structure Used to implement an extension of the If…Then…Else structure. Select Case Structure: used when there are more than two options! This was perfectly illustrated in the Auto Loan Program. They used a select case structure to input the correct interest rates for the five possible credit ratings!

14 Coding a Select Case Statement

15 Coding a Select Case Statement

16 Using Message Boxes Sometimes it becomes important to communicate with the person running your program. –For example: They do something stupid and you want to tell them not to do that anymore! The MessageBox provides the ability to display a message to the user in a pop-up window. The Show() method can be used to display a message with a title bar. Basically, it consists of three parts! For example: MessageBox.Show(“Please enter the customer’s credit rating in the Credit rating list box.”,”No Credit Rating”)

17 Logical Operators The And Logical Operator – is used to combine two or more conditions in an expression. All parts must be true for the True section of code to trigger! For example: If strGender = “M” And intAge < 12 Then MessageBox.Show(“Boys Little League”) End if

18 Logical Operators – Part Two The Or Logical Operator – also used to combine two or more expressions! However, the or operator only requires one condition to be true for the true condition code to trigger! For example: If strGrade = “E” Or intAbsences > 10 then strCredit = “No Credit” End if

19 Combining Logical Operators If X>Y Or T=D And H<3 Or Y=R Then intCount = intCount + 1 End If What order would this line of code execute in? To understand how.NET evaluates this code you’d have to understand the “Rules of Precedence” Unless parenthesis dictate otherwise,.NET reads from left to right and evaluates conditions in this order: –Arithmetic operators –Relational operators –And operators –Or operators

20 Coding with a Logical Operator and String Expressions

21 CONCATENATING TEXT Concatenation -- the process of adding strings together. It is performed with the ampersand [ &] character. –For example: strErrorMessage = “Customers with this credit rating may only borrow “ & strMoney The plus sign (+) can be used instead of the (&) operator. Often times programmers avoid the + sign since it is used in mathematical problems as well.