Chapter 51 ElseIf clause If condition1 Then action1 ElseIf condition2 Then action2 ElseIf condition3 Then action3 Else action4 End If.

Slides:



Advertisements
Similar presentations
Chapter 4 Ch 1 – Introduction to Computers and Java Flow of Control Loops 1.
Advertisements

5.04 Apply Decision Making Structures
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Val Function A Function performs an action and returns a value The expression to operate upon, known as the argument, (or multiple arguments), must be.
Chapter 4 General Procedures
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Chapter 5 - VB.Net by Schneider
Chapter 4 - VB.Net by Schneider1 Chapter 4 General Procedures 4.1 Sub Procedures, Part I 4.2 Sub Procedures, Part II 4.3 Function Procedures 4.4 Modular.
Chapter 41 Sub Procedures, Part II Passing by Value Passing by Reference Local Variables Class-Level Variables Debugging.
Chapter 41 Sub Procedures, Part II (Continue). Chapter 42 Local Variable A variable declared inside a Sub procedure with a Dim statement Space reserved.
Chapter 5 - Visual Basic Schneider1 Chapter 5 Decisions.
Chapter 41 Function Procedures (Continue I). Chapter 42 Lab Sheet 4.7: Code Private Sub btnCalculate_Click(...) _ Handles btnCalculate.Click Dim a, b.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Chapter 41 General Procedures Sub Procedures, Part I Sub Procedures, Part II Function Procedures.
Chapter 51 Select Case block A decision-making structure that simplifies choosing among several actions. Avoids complex nested If constructs. If blocks.
T ODAY ’ S Q UOTE "The computers do what you tell them to do, not what you want them to do. " ( Alexander Atanasov)
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
Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks 5.3 Select Case Blocks.
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.
Chapter 4 - VB 2008 by Schneider1 Chapter 4 – Decisions 4.1 Relational and Logical Operators 4.2 If Blocks 4.3 Select Case Blocks.
Chapter 5 - VB 2005 by Schneider1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks 5.3 Select Case Blocks 5.4 A Case Study: Weekly.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
Revision Exercise: Control Which control will you use to display your name? ____________ Which control will you use to get user’s click action? ____________.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Chapter 5 - VB 2005 by Schneider1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 10: Chapter 6: Slide 1 Unit 10 Sub Procedures and Functions Chapter 6 Sub.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Macro’s Within excel. Most functionality can be driven from VBA VBA is the programming language that runs inside of excel. It uses visual basic as the.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
1 Chapter 4 – Decisions 4.1 Relational and Logical Operators 4.2 If Blocks 4.3 Select Case Blocks 4.4 Input via User Selection.
1 Microsoft® Visual Basic®.NET Language # 2. 2 Flow-Control Statements If … End If Select Case … End Select For… Next Do … Loop Exit.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
情報基礎 A Lecture 12 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Ch. 101 DataTable (Continue) Lab sheet 10.3: Form Display Cities table along with percentage growth.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Introduction to Computer CC111 Week 10 Visual Basic 3 1.
Chapter 5 - VB 2008 by Schneider1 Chapter 5 – Repetition 5.1 Do Loops 5.2 Processing Lists of Data with Do Loops 5.3 For...Next Loops.
Computer Science Up Down Controls, Decisions and Random Numbers.
Chapter 4 - VB 2008 by Schneider1 Chapter 4 – Decisions 4.1 Relational and Logical Operators 4.2 If Blocks 4.3 Select Case Blocks.
1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks 5.3 Select Case Blocks 5.4 A Case Study: Weekly Payroll.
Week 4 Relational and Logical Operators Dr. Jennifer Cunningham.
Lecture 7 Methods (functions and subroutines) Parameter Passing
5.04 Apply Decision Making Structures
Chapter 4 - VB 2008 by Schneider
Chapter 4: Making Decisions.
Chapter 4 (Conditional Statements)
Method.
Topics The if Statement The if-else Statement Comparing Strings
Introduction to VB programming
Chapter 4 – Decisions 4.1 Relational and Logical Operators
The Check Box Control Consists of a small square and a caption
Topics The if Statement The if-else Statement Comparing Strings
Boolean Expressions and If statements
5.2 Sub Procedures, Part I Defining and Calling Sub Procedures
1.الدوال Function 2.الاجراءاتSub Procedure 3.وحده نمطيه Add Module
Selection Statements Chapter 4 Attaway MATLAB 4E.
Chapter 5 - Visual Basic Schneider
Visual Basic – Decision Statements
Controlling Program Flow
Chapter 5 Decisions.
Repetition (While Loop) LAB 9
Selection Statements Chapter 4 Attaway MATLAB 5E.
Presentation transcript:

Chapter 51 ElseIf clause If condition1 Then action1 ElseIf condition2 Then action2 ElseIf condition3 Then action3 Else action4 End If

Chapter 52 Example: Form txtFirstNum txtSecondNum txtResult

Chapter 53 Example: Code Private Sub btnFindLarger_Click(...) _ Handles btnFindLarger.Click Dim num1, num2 As Double num1 = CDbl(txtFirstNum.Text) num2 = CDbl(txtSecondNum.Text) If (num1 > num2) Then txtResult.Text = "Larger number is " & num1 ElseIf (num2 > num1) Then txtResult.Text = "Larger number is " & num2 Else txtResult.Text = "The two are equal." End If End Sub

Chapter 54 Lab Sheet 5.5: Form

Chapter 55 Lab Sheet 5.5: Code Function CalculateFICA(ByVal ytdEarnings As Double, _ ByVal curEarnings As Double) As Double Dim socialSecurityBenTax, medicareTax As Double If (ytdEarnings + curEarnings) <= Then socialSecurityBenTax = * curEarnings ElseIf ytdEarnings < Then socialSecurityBenTax = * ( ytdEarnings) End If medicareTax = * curEarnings Return socialSecurityBenTax + medicareTax End Function

Chapter 56 Lab Sheet 5.5: Output

Chapter 57 Comments When one If block is contained inside another If block, the structure is referred to as nested If blocks. Care should be taken to make If blocks easy to understand.

Chapter 58 Simplified Nested If Statement If cond1 Then If cond1 And cond2 Then If cond2 Then action action End If End If Nested If Less Confusing

Chapter 59 More Comments Some programs call for selecting among many possibilities. Although such tasks can be accomplished with complicated nested If blocks, the Select Case block is often a better alternative.