CHAPTER FIVE Specifying Alternate Courses of Action: Selection Statements.

Slides:



Advertisements
Similar presentations
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
Advertisements

1.
Selection (decision) control structure Learning objective
Microsoft Visual Basic: Reloaded Chapter Five More on the Selection Structure.
Microsoft VB 2005: Reloaded, Advanced Chapter 5 Input Validation, Error Handling, and Exception Handling.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic.NET, Second Edition.
1 Pertemuan 05 Selection Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 4 Decisions and Conditions.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Slide 1 Chapter 2 Visual Basic Interface. Slide 2 Chapter 2 Windows GUI  A GUI is a graphical user interface.  The interface is what appears on the.
Visual Basic Chapter 1 Mr. Wangler.
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Chapter 4: The Selection Structure
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
Chapter 4 The If…Then Statement
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
Chapter 7 Decision Making. Class 7: Decision Making Use the Boolean data type in decision-making statements Use If statements and Select Case statements.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Five More on the Selection Structure.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Chapter 4: The Selection Process in Visual Basic.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Lecture Set 5 Control Structures Part A - Decisions Structures.
Chapter 4: Making Decisions. Understanding Logic-Planning Tools and Decision Making Pseudocode – A tool that helps programmers plan a program’s logic.
Copyright © 2001 by Wiley. All rights reserved. Chapter 4: The Selection Process in Visual Basic Selection Process Two Alternative Structure If..Then..ElseIf.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Five More on the Selection Structure.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
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.
4-1 Chapter 4 The Selection Process in VB.NET. 4-2 Learning Objectives Understand the importance of the selection process in programming. Describe the.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
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.
COMPUTER PROGRAMMING I 3.02 Apply Properties Associated with the Controls.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.
Decisions with Select Case and Strings Chapter 4 Part 2.
Controlling Program Flow with Decision Structures.
Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures.
Copyright © Don Kussee 1410-Ch5 #1031 CNS 1120 Chapter 5 Selection statements 1120-Ch5.PPT.
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.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Visual Basic.NET BASICS Lesson 9 Nested If Statements and Radio Buttons.
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”
Slide 1 Chapter 4 The If…Then Statement  Conditional control structure, also called a decision structure  Executes a set of statements when a condition.
3.02 APPLY PROPERTIES ASSOCIATED WITH THE CONTROLS Computer Programming I.
Visual Basic.NET Windows Programming
Introduction to Programming Lecture 2
Chapter 4 The If…Then Statement
CHAPTER FIVE Decision Structures.
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Chapter 4: The Selection Structure
Chapter 2 Visual Basic Interface
CHAPTER FIVE Decision Structures.
Making Decisions in a Program
Chapter 3: Introduction to Problem Solving and Control Statements
المحاضرة السادسة.
Objectives After studying this chapter, you should be able to:
CIS 16 Application Development Programming with Visual Basic
Introduction to Problem Solving and Control Statements
Visual Basic – Decision Statements
Presentation transcript:

CHAPTER FIVE Specifying Alternate Courses of Action: Selection Statements

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Selection Statements VB Selection Statements –The If…Then…Else statement. –The Select Case statement. Using return value of the MsgBox function VB Selection Controls –Radio Button Defining a group with a container (Form or Group Box) –Check Box

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The Decision-Making Process We must be very precise in writing the criterion and alternative actions for decisions. In a program, –A condition is represented as a logical expression. Meta Statements - Describe compound statement with a single phrase. –An outcome is the result of an evaluated condition. –An appropriate action follows the outcome.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The If…Then...Else Statement The If…Then…Else statement enables a program to handle situations having two outcomes. The statement has three parts: 1.The condition. 2.The statements to perform for a true outcome. 3.The statements to perform for a false outcome.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The If…Then...Else Statement (cont.) The If…Then…Else statement has the following syntax: –If condition Then True statement block –Else False statement block –End If If…Then –If condition Then statementblock –End If

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The If…Then...Else Statement (cont.) –Problem Solving and Pseudocode Problem solving is the process of writing code to perform a required task. Pseudocode is an English-like outline of the logical for program code. –Ex. Request address from user Receive input in a textbox

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Nested If Statements If statements may contain one within another. If (X<Y) And (Y<Z) Then AscOrDesc = “ascending” Else If (X>Y) And (Y>Z) Then AscOrDesc = “descending” Else AscOrDesc = “neither ascending nor descending” End If

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The MsgBox() Function Displays a message box on the screen and waits for the user to click one of the button. Returns a value that indicates which button the user clicked. Syntax: MsgBox(message, mbStyle, title) As MsgBoxResult

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The MsgBox() Function (con’t) MsgBox() Button Combinations –MsgBoxStyle.AbortRetryIgnore (2) –MsgBoxStyle.OKOnly (0) –MsgBoxStyle.OKCancel (1) –MsgBoxStyle.RetryCancel (5) –MsgBoxStyle.YesNo (4) –MsgBoxStyle.YesNoCancel (3) MsgBox() Return Values –vbOK (1) –vbCancel (2) –vbAbort (3) –vbRetry (4) –vbIgnore (5) –vbYes (6) –vbNo (7)

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The RadioButton Control Ensures that user will select only one option –Selection is transferred if user clicks another radiobutton. –Limit the number of radiobuttons to 7 per form. (use list or combo box for more items) Radio button

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The RadioButton Control (cont.) –Properties AppearanceImage CheckAlignImageAlign CheckedText EnabledTextAlign FlatStyleVisible –Events CheckChanged event. –Occurs when the value of the Checked property changes.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The GroupBox Control Allows grouping of RadioButtons into categories of items Descriptive Text to identify the group Group Box

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The GroupBox Control (cont.) –Properties Enabled FlatStyle Text Visible –Events Click CheckChanged

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The CheckBox Control Used when a combination of options may be selected. Check Box

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The CheckBox Control (cont.) –Properties and Events Similar to the RadioButton. CheckState property gets or sets the state of the CheckBox. ThreeState property will allow the user to select an Indeterminate state. CheckBox can respond to a CheckedChanged event.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The CheckBox Control (cont.) –Properties of the CheckBox control CheckAlign Checked CheckState Enabled Text TextAlign ThreeState Visible

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The Select Case Statement Can handle conditions with multiple outcomes. –Syntax and Action of Select Case Select Case testexpression Case expressionlist1 statementblock1 Case expressionlist2 statementblock2 … Case expressionlistN statementblockN Case Else statementblock End Select

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The Select Case Statement (cont.) –Run Time: The Effect of the Select Case Statement First the computer evaluates the test expression. Then it tries to match the resulting value. The search starts at the top expression list. The computer stops at the first match. The corresponding statement block is executed. Control resumes after the End Select. If no match occurs and a Case Else exists, then the Case Else block is executed. Then control resumes after the End Select. If no match occurs and no Case Else exists, then control resumes after the End Select.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The Select Case Statement (cont.) –Ranges Two variations –Use the keyword “To” »Ex. 25 To 37 –Use the keyword “Is” »Ex. Is >= 77 –If versus Select Case If a decision has only two outcomes and the condition can be expressed as a single logical expression, then the If statement is easier to read. If a decision has multiple outcomes that depend on a single expression, then the Select Case is usually easier to read. If the outcomes depend on a number of conditions that may be independent, then embedded If statements are better.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The Exit Sub Statement For decisions where one of the appropriate actions is to stop processing. Causes execution to skip directly to End Sub. Is not limited to If…Then…Else and Select Case statements.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Quick Review What is evaluated to determine the path of execution in a selection statement? What language is used to describe the logical steps (algorithm) when designing a problem solution? Which selection statement enables a program to choose one of two actions based on a condition that evaluates to true or false?

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Quick Review (cont.) Which two controls enable the user to make choices with the GUI? Which control groups a set of choices of which only one can be selected? Which selection statement handles a single condition that may have more than one outcome? Which statement enables a program to stop execution before a procedure is completed?