Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Five More on the Selection Structure.

Slides:



Advertisements
Similar presentations
Chapter 6: The Repetition Structure
Advertisements

Programming with Microsoft Visual Basic 2008 Fourth Edition
Programming with Microsoft Visual Basic th Edition
1.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Chapter 11: Classes and Objects
Programming with Microsoft Visual Basic th Edition
Microsoft Visual Basic: Reloaded Chapter Five More on the Selection Structure.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
Chapter 4: The Selection Structure Programming with Microsoft Visual Basic.NET, Second Edition.
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA By Robert T. Grauer Maryann Barber.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic.NET, Second Edition.
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
An Introduction to Programming with C++ Fifth Edition Chapter 6 More on the Selection Structure.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
MsgBox Function Displays one of Visual Basic’s predefined dialog boxes, which contains a message, one or more command buttons, and an icon After displaying.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition CHAPTER SEVEN SUB AND FUNCTION PROCEDURES.
Chapter Four The Selection Structure
Using the Select Case Statement and the MsgBox Function (Unit 8)
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Chapter 4: The Selection Structure
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Five More on the Selection Structure.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Chapter 12: How Long Can This Go On?
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 2 Creating a User Interface.
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
Chapter 4: Making Decisions. Understanding Logic-Planning Tools and Decision Making Pseudocode – A tool that helps programmers plan a program’s logic.
Working with option button, check box, and list box controls Visual Basic for Applications 13.
Chapter 6: The Repetition Structure
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
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.
CHAPTER FIVE Specifying Alternate Courses of Action: Selection Statements.
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA.
Chapter 5: More on the Selection Structure
Programming with Microsoft Visual Basic th Edition
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 Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
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.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Four The Selection Structure.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
Chapter 10 So Many Paths … So Little Time (Multiple-Alternative Selection Structures) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Chapter Five More on the Selection Structure Programming with Microsoft Visual Basic th Edition.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Chapter 4: Do-It-Yourself Designing (Designing Interfaces)
Chapter 11: Testing, Testing…1, 2, 3
Microsoft Visual Basic 2008: Reloaded Third Edition
More on the Selection Structure
CHAPTER FIVE Decision Structures.
Chapter 4: The Selection Structure
Programming with Microsoft Visual Basic 2008 Fourth Edition
Microsoft Visual Basic 2005 BASICS
CHAPTER FIVE Decision Structures.
Making Decisions in a Program
Objectives After studying this chapter, you should be able to:
CIS 16 Application Development Programming with Visual Basic
Microsoft Visual Basic 2005: Reloaded Second Edition
Presentation transcript:

Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Five More on the Selection Structure

Objectives After studying this chapter, you should be able to: Include a nested selection structure in pseudocode and in a flowchart Code an If/ElseIf/Else selection structure Include a Case selection structure in pseudocode and in a flowchart Code a Case selection structure Include radio buttons in an interface Microsoft Visual Basic 2008: Reloaded, Third Edition2

Objectives (continued) Display a message in a message box Prevent the entry of unwanted characters in a text box Microsoft Visual Basic 2008: Reloaded, Third Edition3

4 Nested Selection Structures Nested selection structure: a selection structure that is completely contained within another selection structure Primary decision: decision made by the outer selection structure Secondary decision: decision made by the inner selection structure

Nested Selection Structures (continued) Microsoft Visual Basic 2008: Reloaded, Third Edition5 Figure 5-1: Sample run of the Voter Eligibility application

Microsoft Visual Basic 2008: Reloaded, Third Edition6 Figure 5-2: Pseudocode and code showing the nested selection structure in the true path

Microsoft Visual Basic 2008: Reloaded, Third Edition7 Figure 5-3: Flowchart showing the nested selection structure in the true path

Microsoft Visual Basic 2008: Reloaded, Third Edition8 Figure 5-4: Pseudocode and code showing the nested selection structure in the false path

Microsoft Visual Basic 2008: Reloaded, Third Edition9 Figure 5-5: Flowchart showing the nested selection structure in the false path

The If/ElseIf/Else Selection Structure Example: a procedure to display a message based on a letter grade Microsoft Visual Basic 2008: Reloaded, Third Edition10

The If/ElseIf/Else Selection Structure (continued) Microsoft Visual Basic 2008: Reloaded, Third Edition11 Figure 5-6: Sample run of the Grade Message application

The If/ElseIf/Else Selection Structure (continued) Microsoft Visual Basic 2008: Reloaded, Third Edition12 Figure 5-7: Two versions of the messageButton’s Click event procedure

Microsoft Visual Basic 2008: Reloaded, Third Edition13 Figure 5-7: Two versions of the messageButton’s Click event procedure (continued)

Microsoft Visual Basic 2008: Reloaded, Third Edition14 The Case Selection Structure Case selection structure: –Used when there are many paths from which to choose –Simpler and clearer than using If/ElseIf/Else –Flowchart symbol is the same as the symbol for If, If/Else, and If/ElseIf/Else

Microsoft Visual Basic 2008: Reloaded, Third Edition15 The Case Selection Structure (continued) Figure 5-8: Pseudocode showing the Case selection structure

Microsoft Visual Basic 2008: Reloaded, Third Edition16 The Case Selection Structure (continued) Case selection structure in a flowchart: –Uses the diamond symbol –One flowline into the diamond, but many flowlines out of the diamond –Each flowline represents a possible path Case selection structure evaluates an expression to determine which path to take Uses the Select Case statement: –Begins with Select Case –Ends with End Select –Has one Case clause for each possible value

Microsoft Visual Basic 2008: Reloaded, Third Edition17 The Case Selection Structure (continued) Figure 5-9: Flowchart showing the Case selection structure

Microsoft Visual Basic 2008: Reloaded, Third Edition18 Figure 5-10: How to use the Select Case statement

Microsoft Visual Basic 2008: Reloaded, Third Edition19 Specifying a Range of Values in an ExpressionList To and Is keywords: specify a range of values in a Case clause’s expression list To : –When you know both the upper and lower bounds of the range Is : –When you know only one end of the range –Used with a comparison operator

Microsoft Visual Basic 2008: Reloaded, Third Edition20 Figure 5-11: Example of using the To and Is keywords in a Select Case statement

Using Radio Buttons RadioButton control: allows the user to select only one of a group of two or more choices RadioButton choices are related but mutually exclusive; only one can be selected Container control: –Isolates a group of radio buttons –Includes GroupBox, Panel, and TableLayout controls Microsoft Visual Basic 2005: Reloaded, Second Edition21

Using Radio Buttons (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition22 Figure 5-12: Sample run of the Gentry Supplies application

Using Radio Buttons (continued) Minimum number of radio buttons in a group is two –Must select a radio button to deselect another Recommended maximum number in a group: seven Windows standard is to set one as the default radio button –Shows as selected when the screen appears –Should be the most likely selection or the first radio button in the group Set the Checked property to True to make it the default radio button Microsoft Visual Basic 2005: Reloaded, Second Edition23

Microsoft Visual Basic 2005: Reloaded, Second Edition24 Figure 5-13: The displayButton’s Click event procedure

Using Radio Buttons (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition25 Figure 5-13: The displayButton’s Click event procedure (continued)

Microsoft Visual Basic 2008: Reloaded, Third Edition26 The MessageBox.Show Method MessageBox.Show method: –Displays a message box with text, one or more buttons, and an icon When a message box is displayed, the program waits until the user selects a button MessageBox.Show returns an integer value indicating which button the user selected DialogResult values include: –Windows.Forms.DialogResult.Yes –Windows.Forms.DialogResult.No

Microsoft Visual Basic 2008: Reloaded, Third Edition27 Figure 5-14: How to use the MessageBox.Show method

The MessageBox.Show Method (continued) Microsoft Visual Basic 2008: Reloaded, Third Edition28 Figure 5-15: Message box displayed by Example 1 in Figure 5-14

The MessageBox.Show Method (continued) Microsoft Visual Basic 2008: Reloaded, Third Edition29 Figure 5-16: Message box displayed by Example 2 in Figure 5-14

Microsoft Visual Basic 2008: Reloaded, Third Edition30 Figure 5-17: How to use the value returned by the MessageBox.Show method

Coding the KeyPress Event Microsoft Visual Basic 2008: Reloaded, Third Edition31 Can prevent a text box from accepting an inappropriate character by coding the text box’s KeyPress event KeyPress event: occurs each time the user presses a key while the control has the focus Use the e parameter’s KeyChar property to determine the pressed key Use the e parameter’s Handled property to cancel the key if it is inappropriate Use ControlChars.Back constant to represent the Backspace key on the keyboard

Coding the KeyPress Event (continued) Microsoft Visual Basic 2008: Reloaded, Third Edition32 Figure 5-18: How to use the KeyPress event

Programming Tutorial Microsoft Visual Basic 2008: Reloaded, Third Edition33 Figure 5-20: User interface

Programming Example Microsoft Visual Basic 2008: Reloaded, Third Edition34 Figure 5-31: User interface

Microsoft Visual Basic 2008: Reloaded, Third Edition35 Summary Selection structures can be nested in either the true or false path of another selection structure Primary decision is made by the outer selection structure, while the secondary decision is made by the inner (nested) selection structure Use If/ElseIf/Else or Case structures when there are several possible alternative outcomes Select Case statement is used to code the Case selection structure

Microsoft Visual Basic 2008: Reloaded, Third Edition36 Summary (continued) Use To keyword to specify a range of valid values when both the lower and upper bounds are known Use Is keyword with a comparison operator to specify a lower or upper bound but not both Use radio buttons to limit the user to one choice from a group of two or more related but mutually exclusive choices MessageBox.Show method allows an application to communicate with the user

Summary (continued) MessageBox.Show method returns an integer indicating which button was chosen by the user Use sentence capitalization for the text message in the MessageBox.Show method, but book title capitalization for the caption Use the KeyPress event of a text box to prevent it from accepting an inappropriate character Use the ControlChars.Back constant to represent the Backspace key on the keyboard Microsoft Visual Basic 2008: Reloaded, Third Edition37