Chapter 10 So Many Paths … So Little Time (Multiple-Alternative Selection Structures) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition.

Slides:



Advertisements
Similar presentations
Programming with Microsoft Visual Basic 2008 Fourth Edition
Advertisements

Programming with Microsoft Visual Basic th Edition
1.
Chapter 11: Classes and Objects
Programming with Microsoft Visual Basic th Edition
Microsoft Visual Basic: Reloaded Chapter Five More on the Selection Structure.
Chapter 4 Decisions and Conditions Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic.NET, Second Edition.
Comparing Numeric Values If Val(Text1.Text) = MaxPrice Then (Is the current numeric value stored in the Text property of Text1 equal to the value stored.
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Ten String Manipulation and Menus.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition CHAPTER SEVEN SUB AND FUNCTION PROCEDURES.
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Chapter Four The Selection Structure
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Chapter 4: The Selection Structure
Tutorial 11 Using and Writing Visual Basic for Applications Code
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Five More on the Selection Structure.
Using the selection structure (Unit 7) Visual Basic for Applications.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Chapter 4: The Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 4: The Selection Structure
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Five More on the Selection Structure.
Chapter 6: The Repetition Structure
Decisions and Debugging Part06dbg --- if/else, switch, validating data, and enhanced MessageBoxes.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Chapter 5: More on the Selection Structure
Programming with Microsoft Visual Basic th Edition
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
1 Week 5 More on the Selection Structure. 2 Nested, If/ElseIf/Else, and Case Selection Structures Lesson A Objectives After completing this lesson, you.
Chapter Four The Selection Structure Programming with Microsoft Visual Basic th Edition.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Computer Programming TCP1224 Chapter 5 The Selection Structure.
Programming with Microsoft Visual Basic th Edition
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?
Chapter 13 Do It, Then Ask Permission (Posttest Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Decisions with Select Case and Strings Chapter 4 Part 2.
Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
Chapter Five More on the Selection Structure Programming with Microsoft Visual Basic th Edition.
Chapter 7 What’s Wrong with It? (Syntax and Logic Errors) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
An Introduction to Programming with C++1 The Selection Structure Tutorial 6.
Course ILT Using complex selection structures Unit objectives Include radio buttons and check boxes in an interface, create and call a user- defined Sub.
Random Functions Selection Structure Comparison Operators Logical Operator
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Chapter 4: Decisions and Conditions
A variable is a name for a value stored in memory.
Chapter 4: Decisions and Conditions
The Selection Structure
Chapter 4: The Selection Structure
Programming with Microsoft Visual Basic 2008 Fourth Edition
An Introduction to Programming with C++ Fifth Edition
Making Decisions in a Program
Chapter 3: Introduction to Problem Solving and Control Statements
Objectives After studying this chapter, you should be able to:
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 5: The Selection Structure
Presentation transcript:

Chapter 10 So Many Paths … So Little Time (Multiple-Alternative Selection Structures) Clearly Visual Basic: Programming with Visual Basic nd Edition

Objectives Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 2 After studying Chapter 10, you should be able to: Code a multiple-alternative selection structure using If/ElseIf/Else Declare a variable using the String data type Convert a string to uppercase or lowercase Code a multiple-alternative selection structure using Select Case Include a radio button in an interface

Which Way Should I Go? Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 3 Multiple-alternative selection structures Can choose from several alternatives Figure 10-1 Contains a problem specification that requires a multiple-alternative selection structure Figure 10-2 Shows two ways of coding the multiple-alternative selection structure from Figure 10-1 Figure 10-3 A third example of the multiple-alternative selection structure

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 4 Figure 10-1 Department code problem specification and algorithm

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 5 Figure 10-2 Two versions of the code for the multiple-alternative selection structure

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 6 Figure 10-3 Fitness for Good problem specification and algorithm

Coding the Fitness for Good Application Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 7 Code algorithm shown in Figure 10-3 Start by opening the application Open the Code Editor window Follow instructions on pages String data type Stores alphanumeric text Can contain letters, numbers, and special characters

Don’t Be So Sensitive Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 8 Case sensitive Uppercase version of a letter not the same as lowercase Unicode Universal coding scheme for characters Assigns a unique numeric value to each character ToUpper method: Converts a string to uppercase ToLower method: Converts a string to lowercase Conversion is temporary in both methods

Don’t Be So Sensitive (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 9 When using the ToUpper method in a comparison: Everything you are comparing should be in uppercase When using the ToLower method in a comparison: Everything you are comparing should be in lowercase

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 10 Figure 10-6 Syntax and examples of the ToUpper and ToLower methods

Don’t Be So Sensitive (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 11 When processing the statement: strCode = txtCode.Text.ToUpper The computer first makes a temporary copy of the string entered in the txtCode control It then converts the copy to uppercase, storing the result in the strCode variable Finally, it removes the copy from its internal memory

What’s the Next Case on the Docket? Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 12 Figure 10-8 shows: The Select Case statement’s syntax How to use the statement to code: A multiple-alternative selection structure that displays a message corresponding to a letter grade Select Case statement Begins with the keywords Select Case, followed by a selectorExpression selectorExpression Can contain any combination of variables, constants, methods, operators, or properties

What’s the Next Case on the Docket? (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition 13 Select Case Statement You can have as many Case clauses as necessary If the Select Case statement includes a Case Else clause: The Case Else clause must be the last clause in the statement Each of the individual Case clauses, except the Case Else clause, must contain an expressionList

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 14 Figure 10-8 Syntax and an example of the Select Case statement

Using Select Case in the Fitness for Good Application Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 15 Code the application using the instructions on pages

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 16 Figure 10-9 btnDisplay control’s Click event procedure

Specifying a Range of Values in a Case Clause’s Expression List Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 17 You can specify a range of values in a Case clause’s expressionList You do this using either the keyword To or the keyword Is To keyword Used when you know both the upper and lower bounds of the range Is keyword Used when you know only one end of the range

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 18 Figure Example of using the To and Is keywords in a Case clause

Coding the ABC Corporation Application Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 19 Follow the instructions on pages

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 20 Figure btnDisplayPrice control’s Click event procedure

Using Radio Buttons Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 21 If/ElseIf/Else and Case forms of the selection structure Often used when coding interfaces that contain radio buttons Radio button Created using the RadioButton tool in the toolbox Allows you to limit the user to only one choice in a group of two or more Default radio button Radio button that represents the user’s most likely choice or the first radio button in the group

Coding the Gentry Supplies Application Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 22 Figure Gentry Supplies shipping chart

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 23 Figure Selection structures entered in the procedure

Summary Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 24 Solutions to some problems require a multiple-alternative selection structure Coding a multiple-alternative selection structure Use either the If...Then...Else statement Or the Select Case statement String comparisons are case sensitive Convert to either uppercase or lowercase before comparing Each character on the computer keyboard Associated with a unique Unicode value

Summary (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 25 To or Is keywords Specify a range of values in Select Case statement Radio buttons Limit the user to one choice from a group of two or more For two groups of radio buttons in an interface: At least one must be placed within a container Boolean value stored in button’s Checked property Determines whether the radio button is selected (True) or unselected (False)