# 1# 1 Nested If Statements in VBA What is a compound condition that we evaluate? What is a Nested If statement? How do we use ElseIf? CS 105 Spring 2010.

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

Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
CS&E 1111 ExIFs IFs and Nested IFs in Excel Objectives: Using the If function in spreadsheets Nesting If functions.
5.04 Apply Decision Making Structures
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
CS0007: Introduction to Computer Programming
Lesson 5 - Decision Structure By: Dan Lunney
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
Control Structures Control structures are used to manage the order in which statements in computer programs will be executed Three different approaches.
Objectives AND logic OR logic Evaluating compound conditions with multiple logical operators Precedence when combining AND and OR operators Efficiency.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Chapter 5: Control Structures II (Repetition)
true (any other value but zero) false (zero) expression Statement 2
Flow of Control MINS298c Fall 1998 Chapter 9. Overview ABAP Programming Structures for: –Iteration –Decisions Control Flow –If … Then –Do & While loops.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
1 Selection Structures. 2 Making Decisions Sample assignment statements to figure worker pay with possible overtime PayAmount = Hours * Rate PayAmount.
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Programming Logic and Design Sixth Edition
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Decision Structures and Boolean Logic
CPS120: Introduction to Computer Science Decision Making in Programs.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Chapter 5 - VB 2005 by Schneider1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
CS105 Lab 9 – Do-While-Loops Announcements MP2 released today! See website for several important announcements/deadlines CS 105 – Fall
MULTIPLE ALTERNATIVES IF… THEN… ELSEIF SELECT CASE.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
ASP-5-1 ASP Control Structures Colorado Technical University IT420 Tim Peterson.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Introduction to branching.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
259 Lecture 11 Spring 2013 Advanced Excel Topics – Loops.
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
LOAN APPLICATION Income High Medium Low Employment References Employed Unemployed Good Bad Education High Low High Low Grant Investigate Further Investigate.
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.
Computer-made Decisions Chapter 3 & 4. Overview u Variable Scope u Conditionals  Relational Operators  AND, OR, NOT u If Statements u MsgBox function.
110 F-1 Decisions and Conditions Chapter 4: We can design a form We can calculate To make our programs more powerful, we need to be able to make choices.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 3 Decision Trees Conditionals.
# 1# 1 CS 105 Spring 2010 If, If Else Statements What does If / Then do? Is Else necessary? What is Pseudocode? Does the computer skip lines of code?
CSC 162 Visual Basic I Programming. Storage Classes Determines the “lifetime” of an identifier Types: –Automatic Default Memory is allocated for the variable.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
 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.
Follow up from lab See Magic8Ball.java Issues that you ran into.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
5.04 Apply Decision Making Structures
Chapter 4: Making Decisions.
Chapter 4 MATLAB Programming
Topics The if Statement The if-else Statement Comparing Strings
JavaScript Selection Statement Creating Array
Topics The if Statement The if-else Statement Comparing Strings
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Program Flow Control Selection & repetition
Chapter 4: Decision Structures and Boolean Logic
Three Special Structures – Case, Do While, and Do Until
Visual Basic – Decision Statements
Selection Statements.
CS 1111 Introduction to Programming Spring 2019
Conditional Statements
Types, Truth, and Expressions (Part 2)
Selection Structures: Single-alternative
Chapter 3: Selection Structures: Making Decisions
Chapter 4: Decision Structures and Boolean Logic
Presentation transcript:

# 1# 1 Nested If Statements in VBA What is a compound condition that we evaluate? What is a Nested If statement? How do we use ElseIf? CS 105 Spring 2010

# 2# 2 Compound Conditions -- Review If intA = 26 intB = 34 intC = 16 Then intA < intB is TRUE intB < intC is FALSE (intA < intB) And (intB < intC) is FALSE (intA < intB) Or (intB < intC) is TRUE Not (intB < intC)is TRUE

# 3# 3 CS 105 Spring 2010 Simple Use of NOT If NOT (mintRow < 3) Then Exit Sub End If

# 4# 4 CS 105 Spring 2010 Example of NOT – Track Meet Scores Private Sub cmdNotExample_Click() If Not (intUIUC < intMSU) And Not (intUIUC < intIU) Then Range(“C5").Value = "We won, We won!" End If End Sub

# 5# 5 CS 105 Spring 2010 Nested If Statements Use Nested If when you have multiple decisions, as in a decision tree. You use Case Statements when a variable has multiple values (we will cover Case Statements next)

# 6# 6 CS 105 Spring 2010 Putting it all together with Excel We named this cell “Total”

# 7# 7 CS 105 Spring 2010 What does this code do? Private Sub cmdEvaluate_Click() If Range("Total").Value > 5000 Then Range("Total").Interior.ColorIndex = 6 Else If Range("Total").Value > 3000 Then Range("Total").Interior.ColorIndex = 8 Else Range("Total").Interior.ColorIndex = 4 End If End Sub

# 8# 8 CS 105 Spring 2010 If the first condition is True… Private Sub cmdEvaluate_Click() If Range("Total").Value > 5000 Then Range("Total").Interior.ColorIndex = 6 Else If Range("Total").Value > 3000 Then Range("Total").Interior.ColorIndex = 8 Else Range("Total").Interior.ColorIndex = 4 End If End Sub

# 9# 9 CS 105 Spring 2010 What does this code do? Private Sub cmdEvaluate_Click() If Range("Total").Value > 5000 Then Range("Total").Interior.ColorIndex = 6 ElseIf Range("Total").Value > 3000 Then Range("Total").Interior.ColorIndex = 8 Else Range("Total").Interior.ColorIndex = 4 End If End Sub

# 10 CS 105 Spring 2010 Add the comments to an Else/If Private Sub cmdEvaluate_Click() If Range("Total").Value > 5000 Then 'Yellow should show the profit! Range("Total").Interior.ColorIndex = 6 ElseIf Range("Total").Value > 3000 Then ' light blue gives us a warning Range("Total").Interior.ColorIndex = 8 Else 'We feel sick...green Range("Total").Interior.ColorIndex = 4 End If End Sub

# 11 CS 105 Spring 2010 Nested If Flowchart Execute next statement after End If in procedure Test Condition If False True Statements below the If, then go to below final End If Test Condition True Statements below Else Statements below ElseIf, then go to below final End If ElseIf False

# 12 Testing our knowledge If the condition is FALSE do we A. Skip over code and go to Else or ElseIf? B. Execute the next line of code? CS 105 Spring 2010

# 13 CS 105 Spring 2010 To Summarize: What is a compound condition that we evaluate? What is a Nested If statement? How do we use ElseIf?

# 14 NO NO NO NO NO NO NO CS 105 Spring 2010

# 15 YES YES YOU SKIP LINES OF CODE! CS 105 Spring 2010