Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

2 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

3 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

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

5 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

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

7 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 163-164 String data type Stores alphanumeric text Can contain letters, numbers, and special characters

8 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

9 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

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

11 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

12 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

13 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

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

15 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 169-170

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

17 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

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

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

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

21 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

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

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

24 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

25 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)


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

Similar presentations


Ads by Google