OF COURSE I DON'T LOOK BUSY... I DID IT RIGHT THE FIRST TIME

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

CS0004: Introduction to Programming Select Case Statements and Selection Input.
5.04 Apply Decision Making Structures
Conditional Statements If these were easy then everyone would them!
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
OF COURSE I DON'T LOOK BUSY... I DID IT RIGHT THE FIRST TIME
The switch StatementtMyn1 The switch Statement Sometimes there can be a multiple-choice situation, in which you need to execute a particular set of statements.
Apply Sub Procedures/Methods and User Defined Functions
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Conditional Statements While writing a program, there may be a situation when you need to adopt one path out of the given two paths. So you need to make.
110-G1 Motivation: Within a program, may have to perform the same computation over and over Many programs share the same computation (e.g. sorting) To.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Chapter 5: More on the Selection Structure
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
JavaScript, Fourth Edition
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
CW-V1 SDD 0901 Principals of Software Design and Development Loops Starter: Water JugsWater Jugs.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
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.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
Introduction to Programming Lecture 2 Msury Mahunnah, Department of Informatics, Tallinn University of Technology.
Variables in VB.NET. Variables  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can.
31/01/ Selection If selection construct.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
A First Book of C++ Chapter 4 Selection. Objectives In this chapter, you will learn about: –Relational Expressions –The if-else Statement –Nested if Statements.
Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures.
5.02B Decision Making Structure (part 2). Compound Boolean Expressions.
Adding Code to the Option Button. Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
Lesson 5 Exponentiation,Order of Operations and Error Handling.
Visual Basic.NET BASICS Lesson 9 Nested If Statements and Radio Buttons.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
An Introduction to Programming with C++1 The Selection Structure Tutorial 6.
Chapter 6 Controlling Program Flow with Looping Structures.
Computer Science Up Down Controls, Decisions and Random Numbers.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
Welcome to Computer Programming II! Computer Programming II Summer 2015.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
© 2006 Lawrenceville Press Slide 1 Chapter 5 The If…Then Statement (One-Way)  Conditional control structure, also called a decision structure  Executes.
Visual Basic Fundamental Concepts
Introduction to Programming Lecture 2
5.04 Apply Decision Making Structures
IE 8580 Module 4: DIY Monte Carlo Simulation
ME 142 Engineering Computation I
COMP 14 Introduction to Programming
Clearly Visual Basic: Programming with Visual Basic nd Edition
Visual Basic 6 (VB6) Data Types, And Operators
3.01 Apply Controls Associated With Visual Studio Form
CHAPTER FIVE Decision Structures.
3.01 Apply Controls Associated With Visual Studio Form
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
If, else, elif.
Introduction to Programming for Mechanical Engineers (ME 319)
Microsoft Visual Basic 2005 BASICS
CHAPTER FIVE Decision Structures.
Visual Basic..
Chapter 3: Introduction to Problem Solving and Control Statements
Learning Outcomes –Lesson 4
Visual Basic – Decision Statements
Let’s all Repeat Together
Java Programming with BlueJ Objectives
Introduction to Visual Basic 2010
Presentation transcript:

OF COURSE I DON'T LOOK BUSY... I DID IT RIGHT THE FIRST TIME

Select…Case

Using Select Case Visual Basic provides a statement especially for multi-way decisions, called Select Case Statement

Definition A statement in which you specify a variable to test and then list a number of cases that you want to test for.

Syntax: Select Case intValue Case 1 [do this] Case Is < 2 Case 3, 4 Case Else End Select

How it works! In a Select Case statement: You specify a variable to test. List a number of cases that you want to test for. VB will: Evaluate each Case statement. If the value matches (or evaluates as True) the value contained in the original variable then the block of code between the Case statement is executed. The Select Case statement ends with an End Select statement. As a default, the code under the Case Else statement will be applied if no other Case statement catches it first. If the value in the variable matches more than one Case statement, only the first match will be executed.

Example: 'Select type of vehicle to rent Select Case intPassengers Case 1 To 2 lblOutput.Caption = "You should rent a compact car." Case 3 To 4 lblOutput.Caption = "You should rent a full size car." Case 5 To 7 lblOutput.Caption = "You should rent a minivan." Case 8 To 15 lblOutput.Caption = "You should rent a 15 passenger van." Case Is > 15 lblOutput.Caption = "You should rent a bus." Case Else lblOutput.Caption = "Incorrect data" End Select

Visual Basic Program Open VB and create a new form that looks like the following:

Dim intPassengers As Integer Double click the OK button and enter the following code: Dim intPassengers As Integer intPassengers=Val(txtPassengers.Text)

'Select type of vehicle to rent Select Case intPassengers Case 1 To 2 lblOutput.Caption = "You should rent a _ compact car." Case 3 To 4 lblOutput.Caption = "You should rent a full _ size car." Case 5 To 7 lblOutput.Caption = "You should rent a _ minivan."

Case 8 To 15 lblOutput.Caption = "You should rent a _ 15 passenger van." Case Is > 15 lblOutput.Caption = "You should rent a _ bus." Case Else lblOutput.Caption = "Incorrect data" End Select

Close the Code window and run the program. Key 14 as the number of passengers and click the OK button. What is output? Save your program. Call me when your program is running and I’ll check into my book.

Summary The Select Case statement allows you to make multi-way selections. The Case statements in a Select Case can test a range or use conditional operators. Conditional operators in a Case statement must include the Is keyword. As a default, the Case Else statement is applied if no other Case is true.

Homework! Answer True/False: ___ To use a conditional operator in a Case statement, you must use the keyword Is. ___ The Select Case statement ends with an End Select statement. ___ Code under the Case Else statement is the default case in a Select Case statement.