The Select Case Statement. Slide 4- 2 Select Case Statement Similar to If…Then…ElseIf  Performs a series of tests  Conditionally executes the first.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Fundamental of C programming
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
5.04 Apply Decision Making Structures
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 1 Unit 7 Decisions (Cont.) and Message Boxes Chapter.
Creating PHP Pages Chapter 7 PHP Decisions Making.
An Introduction to Programming with C++ Fifth Edition Chapter 5 The Selection Structure.
Making Decisions and Working With Strings
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 4- 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 4- 1.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Function tax and buy_one double tax (double price, double tr) { return price*tr; } double buy_one() { double p; cout > p;
Saturday May 02 PST 4 PM. Saturday May 02 PST 10:00 PM.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Making Decisions.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
CSCI Chapter 4 Making Decisions and Working with Strings Instructor: Bindra Shrestha University of Houston – Clear Lake.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 4 Making Decisions and Working With Strings.
Chapter 3: Using Variables and Constants
© 1999, by Que Education and Training, Chapter 5, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
CIS 115 Lecture 7 Selection / Decisions.
Copyright © 2014 Pearson Education, Inc. Chapter 4 Making Decisions.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Lecture Set 5 Control Structures Part A - Decisions Structures.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Chapter 4 Making Decision Csc 125 C++ programming language Fall 2005.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Making Decisions.
COMPUTER PROGRAMMING II SUMMER 2011 Visual Basic to C#
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
22/11/ Selection If selection construct.
1 More Control Structures if and switch (Chap. 8) do-while and forever loops (Chap. 9)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter Making Decisions and Working With Strings 4.
Chapter Making Decisions 4. Relational Operators 4.1.
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.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 4 Making Decisions.
InputBox. Format of the InputBox Function Prompt - message to the user Title - text for the box's title bar Default - default text for user's input Xpos.
Pay Example (PFirst98) Please use speaker notes for additional information!
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
Calvin College Controlling Behavior The if, switch and for Statements.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Expressions Methods if else Statements Loops Potpourri.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
Murach’s Visual Basic 2008, C7, modified or added© 2008, Mike Murach & Associates, Inc. Slide 1.
2 nd Semester Module3 Selection Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Use TryParse to Validate User Input
5.04 Apply Decision Making Structures
Chapter 4: Making Decisions.
The Selection Structure
Use TryParse to Validate User Input
Chapter 4: Making Decisions.
Javascript Conditionals.
An Introduction to Programming with C++ Fifth Edition
Tutorial 12 – Security Panel Application Introducing the Select Case Multiple-Selection Statement Outline Test-Driving the Security Panel Application.
Conditions and Ifs BIS1523 – Lecture 8.
Chapter 4 Making Decisions.
Conditionals.
Microsoft Visual Basic 2005: Reloaded Second Edition
STARTING OUT WITH Visual Basic 2008
CHAPTER 4: Conditional Structures
Topics Introduction to Repetition Structures
Ch 3 Type Conversion Yonglei Tao.
Presentation transcript:

The Select Case Statement

Slide 4- 2 Select Case Statement Similar to If…Then…ElseIf  Performs a series of tests  Conditionally executes the first true condition Select Case is different in that:  A single test expression may be evaluated  The test expression is listed once  The possible values of the expression are then listed with their conditional statements Case Else may be included and executed if none of the values match the expression

Slide 4- 3 Find Day of Week With Select Case Select Case CInt(txtInput.Text) Case 1 MessageBox.Show("Day 1 is Monday.") Case 2 MessageBox.Show("Day 2 is Tuesday.") Case 3 MessageBox.Show("Day 3 is Wednesday.") Case 4 MessageBox.Show("Day 4 is Thursday.") Case 5 MessageBox.Show("Day 5 is Friday.") Case 6 MessageBox.Show("Day 6 is Saturday.") Case 7 MessageBox.Show("Day 7 is Sunday.") Case Else MessageBox.Show("That value is invalid.") End Select

Slide 4- 4 Select Case With Multiple Values Select Case strAnimal Case "Dogs", "Cats" MessageBox.Show ("House Pets") Case "Cows", "Pigs", "Goats" MessageBox.Show ("Farm Animals") Case "Lions", "Tigers", "Bears" MessageBox.Show ("Oh My!") End Select

Slide 4- 5 Select Case with Operators Select Case intScore Case Is >= 90 strGrade = “A” Case 80 to 89 strGrade = “B” Case 70 to 79 strGrade = “C” Case 60 to 69 strGrade = “D” Case 0 to 59 strGrade = “F” Case Else MessageBox.Show(“Invalid Score”) End Select

Calculate Commission 6

Introduction to Input Validation

Slide 4- 8 Validation Example Output is only as good as the input  “Garbage in, garbage out” Input validation is the process of inspecting user input to see that it meets certain rules The TryParse method verifies that an input value is in a valid numeric or date format Decision structures are often used to validate input

Slide 4- 9 The TryParse Method Converts an input value to another format  Verifies that input of integers, decimals, dates, etc., are entered in an acceptable format  Returns Boolean value indicating True if conversion successful  Returns False if unsuccessful Each numeric variable type has a TryParse method Date & Boolean types include the TryParse method as well

Slide Verify Integer Entry With TryParse Use Integer.TryParse method to convert value  txtInput.Text contains numeric string to convert  intResult receives converted value  TryParse returns True if input is an integer  TryParse returns False if input is not an integer Dim intResult As Integer If Integer.TryParse(txtInput.Text, intResult) Then lblMessage.Text = "Success!" Else lblMessage.Text = "Error: an integer was not found" End If

Slide Verify Date Entry With TryParse Use Date.TryParse method to convert value  txtInput.Text contains date string to convert  datBirth receives converted value  TryParse returns True if input in date format  TryParse returns False if input not a valid date  Not used so Then clause indicates invalid date Dim datBirth As Date If Not Date.TryParse(txtInput.Text, datBirth) Then lblMessage.Text = “Not a valid date!“ End If

Slide Using If To Check Range of Values ' Validate the input to ensure that ' no negative numbers were entered. If decSales < 0 Or decAdvance < 0 Then MessageBox.Show("Please enter positive numbers" & _ " for sales and/or advance pay.“, “Error”) EndIf Decision structures often used to validate input Example verifies that entries for both decSales and decAdvance are positive numbers