Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Advertisements

1.
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
Working with Large Worksheets, Charting, and What-If Analysis
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
Creating, Formatting, and Editing a Word Document with a Picture
Microsoft Visual Basic 2008 CHAPTER FIVE Mobile Applications Using Decision Structures.
Microsoft Visual Basic 2012 CHAPTER TEN Incorporating Databases with ADO.NET.
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 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Visual Basic 2008 CHAPTER FIVE Mobile Applications Using Decision Structures.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 8: String Manipulation
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.
CHAPTER SIX.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
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.
Chapter 2 Creating a Research Paper with References and Sources Microsoft Word 2013.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Five More on the Selection Structure.
Microsoft Expression Web-Illustrated Unit I: Working with Tables.
Chapter 6 Generating Form Letters, Mailing Labels, and a Directory
Office 2003 Advanced Concepts and Techniques M i c r o s o f t Access Project 5 Enhancing Forms with OLE Fields, Hyperlinks, and Subforms.
Chapter 4: The Selection Process in Visual Basic.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Office 2003 Advanced Concepts and Techniques M i c r o s o f t Access Project 5 Enhancing Forms with OLE Fields, Hyperlinks, and Subforms.
Microsoft Office 2007 Access Chapter 6 Using Macros, Switchboards, PivotTables, and PivotCharts.
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.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Five More on the Selection Structure.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Chapter 1 Creating a Worksheet and a Chart
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
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.
Microsoft Visual Basic 2012 CHAPTER ELEVEN Multiple Classes and Inheritance.
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.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Visual Basic 2005 CHAPTER 5 Mobile Applications Using Decision Structures.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
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 FOUR Variables and Arithmetic Operations.
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”
Microsoft Visual Basic 2010 CHAPTER FOUR Variables and Arithmetic Operations.
Variables and Arithmetic Operations
3.01 Apply Controls Associated With Visual Studio Form
CHAPTER FIVE Decision Structures.
3.01 Apply Controls Associated With Visual Studio Form
Enhancing Forms with OLE Fields, Hyperlinks, and Subforms
Using Procedures and Exception Handling
CHAPTER FIVE Decision Structures.
Variables and Arithmetic Operations
Presentation transcript:

Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures

5 Chapter 5: Decision Structures2 Objectives ►Use the GroupBox object ►Place RadioButton objects in applications ►Display a message box ►Make decisions using If…Then statements ►Make decisions using If…Then…Else statements ►Make decisions using nested If statements

5 Chapter 5: Decision Structures3 Objectives ►Make decisions using logical operators ►Make decisions using Case statements ►Insert code snippets ►Test input to ensure a value is numeric

5 Chapter 5: Decision Structures4 Using the GroupBox Object ►Drag the GroupBox object in the Containers category of the Toolbox over the Form object to the approximate location where you want to place the GroupBox object on the Form object ►When the pointer is in the correct location, release the object. With the GroupBox object selected, scroll in the Properties window to the (Name) property. Double-tap or double-click in the right column of the (Name) property, and then enter the desired name. Double-tap or double-click in the right column of the Text property to change the caption of the GroupBox object. Enter the desired text. Click to the right of the Size property of the GroupBox object and enter the deisired size ►Change the Font property to Goudy Old Style, Regular, 12 points. Change the BackColor property to White

5 Chapter 5: Decision Structures5 Using the GroupBox Object

5 Chapter 5: Decision Structures6 Adding the RadioButton Objects ►Drag one RadioButton object from the Toolbox to the GroupBox object. Drag a second RadioButton object from the Toolbox into the GroupBox object, and use blue snap lines to align and separate the RadioButton objects vertically ►Release the RadioButton object to place it within the GroupBox object. Using the same technique, add a third RadioButton object

5 Chapter 5: Decision Structures7 Adding the RadioButton Objects ►Name the RadioButton objects by selecting a RadioButton object, double-tapping or double- clicking in the right column of the (Name) property in the Properties window, and entering the name. Change the Text property for each RadioButton by double-tapping or double-clicking in the right column of the Text property and typing Pine for the first RadioButton, Oak for the second RadioButton and Cherry for the third RadioButton

5 Chapter 5: Decision Structures8 Adding the RadioButton Objects

5 Chapter 5: Decision Structures9 Windows Application Container Objects

5 Chapter 5: Decision Structures10 Displaying a Message Box

5 Chapter 5: Decision Structures11 Displaying a Message Box

5 Chapter 5: Decision Structures12 Displaying a Message Box

5 Chapter 5: Decision Structures13 Displaying a Message Box

5 Chapter 5: Decision Structures14

5 Chapter 5: Decision Structures15 Message Box IntelliSense ►In the code editing window, inside the event handler you are coding, type msg to display MsgBox in the IntelliSense list ►Press the tab key to select MsgBox from the IntelliSense list. Type the following text: (“You have been disconnected from the Internet”, m) ►Select the MsgBoxStyle.AbortRetryIgnore argument by pressing the up arrow until the correct argument is highlighted. Type a comma. Then type "ISP” and a right parenthesis ►Tap or click the Start Debugging button on the Standard toolbar

5 Chapter 5: Decision Structures16 Displaying a Message Box

5 Chapter 5: Decision Structures17 Making Decisions with Conditional Statements: Using an If…Then Statement ►A decision structure is one of the three fundamental control structures used in computer programming ►When a condition is tested in a Visual Basic program, the condition either is true or false

5 Chapter 5: Decision Structures18 Relational Operators

5 Chapter 5: Decision Structures19 Relational Operators ►With the insertion point located in the correct location in the code, type if and then press the SPACEBAR ►Type inta to select the variable named intAge in the IntelliSense list. Then, type >=18 as the condition to be tested. Press the ENTER key ►On the blank line, enter the statement that should be executed when the condition is true. To place the message, “You are old enough to vote” in the Text property of the lblVotingEligibility Label object, insert the code shown in Figure 5-33 on page 303. Remember to use IntelliSense to reference the lblVotingEligibility Label object

5 Chapter 5: Decision Structures20 Comparing Strings ►A string value comparison compares each character in two strings, starting with the first character in each string

5 Chapter 5: Decision Structures21 Comparing Different Data Types ►Every type of data available in Visual Basic can be compared Different numeric types can be compared to each other A single string character can be compared to a Char data type

5 Using the If…Then…Else Statement Chapter 5: Decision Structures22

5 Chapter 5: Decision Structures23 Using the If…Then…ElseIf Statement

5 Nested If Statements Chapter 5: Decision Structures24

5 Nested If Statements Chapter 5: Decision Structures25

5 Nested If Statements Chapter 5: Decision Structures26

5 Chapter 5: Decision Structures27 Matching If, Else, and End If Entries ►If statements must be fully contained within the outer If statement ►Place the correct executing statements with the If and Else statements within the nested If statement This illustration shows incorrect logic

5 Testing the Status of a RadioButton Object in Code Chapter 5: Decision Structures28

5 Chapter 5: Decision Structures29 Block-Level Scope ►Scope is defined by where the variable is declared within a program ►Within an event handler, an If…Then…Else statement is considered a block of code ►Variables can be declared within a block of code The variable can be referenced only within the block of code where it is declared

5 Chapter 5: Decision Structures30 Using Logical Operators ►When more than one condition is included in an If...Then...Else statement, the conditions are called a compound condition

5 Using the And Logical Operator Chapter 5: Decision Structures31

5 Using the Or Logical Operator Chapter 5: Decision Structures32

5 Using the Not Logical Operator Chapter 5: Decision Structures33

5 Chapter 5: Decision Structures34 Other Logical Operators

5 Chapter 5: Decision Structures35 Order of Operations for Logical Operators

5 Chapter 5: Decision Structures36 Select Case Statement ►In some programming applications, different operations can occur based upon the value in a single field

5 Select Case Statement Chapter 5: Decision Structures37

5 Chapter 5: Decision Structures38 Select Case Test Expressions

5 Chapter 5: Decision Structures39 Using Relational Operators in a Select Case Statement

5 Using Ranges in Select Case Statements Chapter 5: Decision Structures40

5 Chapter 5: Decision Structures41 Selecting Which Decision Structure to Use ►You might need to determine if you should use the Select Case statement or the If...Then...ElseIf statement to solve a problem ►Generally, the Select Case statement is most useful when more than two or three values must be tested for a given variable ►The If...Then...ElseIf statement is more flexible More than one variable can be used in the comparison Compound conditions with the And, Or, and Not logical operators can be used

5 Chapter 5: Decision Structures42 Code Snippets ►Press and hold or right-click the line in the code where you want to insert the snippet ►Tap or click Insert Snippet on the shortcut menu ►Double-tap or double-click the folder Code Patterns - If, For Each,Try Catch, Property, etc, which contains commonly used code such as the If... Then... Else statement ►Double-tap or double-click the Conditionals and Loops folder because an If...Then...Else statement is a conditional statement ►Double-tap or double-click the If...Else...End If Statement code snippet

5 Chapter 5: Decision Structures43 Code Snippets

5 Chapter 5: Decision Structures44 Validating Data ►Developers should anticipate that users will enter invalid data ►Developers must write code that will prevent the invalid data from being used in the program to produce invalid output

5 Chapter 5: Decision Structures45 Testing Input to Determine If the Value Is Numeric ►The Visual Basic IsNumeric function can check the input value to determine if the value can be converted into a numeric value such as an Integer or Decimal data type

5 Chapter 5: Decision Structures46 Checking for a Positive Number

5 Program Design Chapter 5: Decision Structures47

5 Program Design Chapter 5: Decision Structures48

5 Program Design Chapter 5: Decision Structures49

5 Chapter 5: Decision Structures50 Chapter Summary ►Use the GroupBox object ►Place RadioButton objects in applications ►Display a message box ►Make decisions using If…Then statements ►Make decisions using If…Then…Else statements ►Make decisions using nested If statements

5 Chapter 5: Decision Structures51 Chapter Summary ►Make decisions using logical operators ►Make decisions using Case statements ►Insert code snippets ►Test input to ensure a value is numeric

Microsoft Visual Basic 2012 CHAPTER FIVE COMPLETE Decision Structures