Processing Decisions Chapter 3. If…Then…Else… Statements If decSalesAmount > 1000 Then sngTaxRate =.05 Else sngTaxRate =.07 End If.

Slides:



Advertisements
Similar presentations
Visual Basic Statements Chapter 5. Relational Operators  OperationSymbol  Equal  =  Less than  <  Greater than  >  Not equal   Less than.
Advertisements

5.04 Apply Decision Making Structures
1.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 1 Unit 7 Decisions (Cont.) and Message Boxes Chapter.
Microsoft Visual Basic: Reloaded Chapter Five More on the Selection Structure.
Chapter 4 Decisions and Conditions Programming In Visual Basic.NET.
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.
VB.Net Introduction - 2. Counter Example: Keep track the number of times a user clicks a button Need to declare a variable: Dim Counter As Integer Need.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Comparing Numeric Values If Val(Text1.Text) = MaxPrice Then (Is the current numeric value stored in the Text property of Text1 equal to the value stored.
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Microsoft Visual Basic 2008 CHAPTER FIVE Mobile Applications Using Decision Structures.
© 1999, by Que Education and Training, Chapter 5, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
CIS162AD - C# Decision Statements 04_decisions.ppt.
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Chapter 4: The Selection Structure
A453 Exemplar Password Program using VBA
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Chapter 7 Decision Making. Class 7: Decision Making Use the Boolean data type in decision-making statements Use If statements and Select Case statements.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Five More on the Selection Structure.
Decision Structures and Boolean Logic
Chapter 4: The Selection Process in Visual Basic.
Chapter 4: The Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 4: The Selection Structure
Chapter 4 Controlling the Flow Adapted From: Starting Out with Visual Basic 2012 (Pearson)
Lecture Set 5 Control Structures Part A - Decisions Structures.
Selection Structure If... Then.. Else Case. Selection Structure Use to make a decision or comparison and then, based on the result of that decision or.
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.
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
Decisions and Debugging Part06dbg --- if/else, switch, validating data, and enhanced MessageBoxes.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
CHAPTER FIVE Specifying Alternate Courses of Action: Selection Statements.
Chapter 5: More on the Selection Structure
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Computer-made Decisions Chapter 3 & 4. Overview u Variable Scope u Conditionals  Relational Operators  AND, OR, NOT u If Statements u MsgBox function.
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.
Pay Example (PFirst98) Please use speaker notes for additional information!
Microsoft Visual Basic 2005 CHAPTER 5 Mobile Applications Using Decision Structures.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
5.1 Introduction Problem Solving –Requires understanding of: Building blocks Program-construction principles BZUPAGES.COM.
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.
Visual Basic.net Functions. Function (Defined) A procedure that returns a value when called.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Controlling Program Flow with Decision Structures.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
Chapter 10 So Many Paths … So Little Time (Multiple-Alternative Selection Structures) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
1 4.2 Selection Logical Operators. 2 Learning Objectives Explain how the logical operator AND Boolean statements works. Directly testing if text boxes.
CSC 162 Visual Basic I Programming. String Functions LTrim( string ) –Removes leading spaces from the left side of string RTrim( string ) –Removes trailing.
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.
Chapter 4: Decisions and Conditions
Chapter 4: Decisions and Conditions
Chapter 4: Making Decisions.
CHAPTER FIVE Decision Structures.
Topics The if Statement The if-else Statement Comparing Strings
IS 350 Decision-making.
Chapter 4: Making Decisions.
CHAPTER FIVE Decision Structures.
Making Decisions in a Program
Topics The if Statement The if-else Statement Comparing Strings
WEB PROGRAMMING JavaScript.
Microsoft Visual Basic 2005: Reloaded Second Edition
Presentation transcript:

Processing Decisions Chapter 3

If…Then…Else… Statements If decSalesAmount > 1000 Then sngTaxRate =.05 Else sngTaxRate =.07 End If

Nested If Statements Test for multiple conditions with multiple results. Job level is based on salary. < – Administrative > – Senior Managers All Others - Managers

Nested If Statements If decSalary > Then –If decSalry > Then lblLevel.Text = “Senior Manager” –Else lblLevel.Text = “Manager” –End If Else –lblLevel.Text = “Administrative” End If

Nested If Statements If decSalary <= Then lblLevel.Text = “Administrative” Else –If decSalry <= Then lblLevel.Text = “Manager” –Else lblLevel.Text = “Senior Manager” –End If End If

If ElseIf Else Statements If condition Then statements ElseIf elseifcondition Then elseifstatements Else elsestatements End If

If ElseIf Else Statements If decSalary < Then lblLevel.Text = “Administrative” ElseIf decSalry <= Then lblLevel.Text = “Manager” Else lblLevel.Text = “Senior Manager” End If

If ElseIf Else Example Bonus is a percentage of salary depending on their performance rating. RatingBonus 310% 27.5% 15%

If ElseIf Else Example If intRating = 3 Then sngBonus =.1 ElseIf intRating = 2 Then sngBonus =.075 ElseIf intRating = 1 Then sngBonus =.05 Else sngBonus = 0 End If

Message Box Function MsgBox “Prompt”,[Buttons], [“Title”] Prompt is the message displayed. Buttons are the choice of buttons and/or icon that appears in the message box. Title is the text on the title bar of the message box.

MessageBoxStyle Values EnumerationValueDescription OKOnly0 (Default)1 Button OKCancel12 Buttons AbortRetryIgnore23 Buttons YesNoCancel33 Buttons YesNo42 Buttons Retry Cancel52 Buttons

MessageBoxStyle Icon Values EnumerationValueDescription Critical16Critical Icon Question32Question Mark Exclamation48Exclamation Point Information64Information Icon

MessageBoxStyle Default Button Values EnumerationValueDescription Default Button 10 (default) First Button is Default Default Button 2256Second Button Default Button 3512Third Button

MessageBoxStyle Modality Values EnumerationValueDescription ApplicationModal0 (default)User must respond to the message box before continuing with this application. SystemModal4096All applications are suspended until user responds to message box.

MessageBoxStyle Window Settings Values EnumerationValueDescription MsgBoxSet Foreground 65536Window in front. MsgBoxRight524288Text is Right Aligned. MsgBoxRtlReading Text appears right to left (other language).

Setting Enumerations YesNo 4 Question 32 MsgBoxRight Sum intButtons = MsgBox( “Yes or No?”, intButtons, “Clarification”)

YesNo 4 Critical 16 DefaultButton2 256 Sum 276 intButtons = 276 MsgBox( “Do you want to exit?”, intButtons, “Exit?”) Setting Enumerations

MessageBox Return Values Button PushedValueConstant OK1vbOK Cancel2vbCancel Abort3vbAbort Retry4vbRetry Ignore5vbIgnore Yes6vbYes No7vbNo

btnExit_Click Dim intResponse as Integer intResponse = MsgBox(“Do you want to exit?”, MsgBoxStyle.Exclamation + MsgBoxStyle.DefaultButton2 + MsgBoxStyle.YesNo, “Exit?) If intResponse = vbYes Then End End IF

Radio Buttons A Radio button is a control for selecting one option from a list of possible options. A Group box assigns a set of radio buttons to a group. A group of radio buttons can only have one button selected. The selected button’s Checked property is set to true.

Grouped Radio Buttons Create the group box first. Create the radio buttons inside the group box. This assures only one radio button in the group can be selected.

Check Box Control A Check box is a control that indicates whether a specific option is selected or not. Any number of check boxes in a group can be selected. Group boxes may or may not be used. A check mark appears in the box. Its Checked property is set to True.

Radio Buttons If rdbAdmin.Checked Then –strLevel = “Administrative” & vbCrLf ElseIf rdbMgr.Checked Then –strLevel = “Manager” & vbCrLf Else –strLevel = “Senior Manager” & vbCrLf End If

Check Boxes If chkMedical.Checked Then –strBenefits = vbCrLf & “Medical Insurance” End If If chkLife.Checked Then –strBenefits = strBenefits & vbCrLf & “Life Insurance” End If If chk401K.Checked Then –strBenefits = strBenefits & vbCrLf & “401K” End If

Data Validation Missing Data If txtData.Text <> “” Then –MsgBox(“You entered: “ & txtData.Text, MsgBoxStyle.Information, “Data is Valid”) Else –MsgBox(“Data is required. Please try again.”, MsgBoxStyle.Critical, “Invalid Data”) End If

IsNumeric Function If the Val function encounters empty or invalid text string it converts the string to 0. IsNumeric function checks a text string and determines if it can be evaluated as a number. Returns a value of True or False. IsNumeric(expression)

Data Validation Non-numeric Data If IsNumeric(txtData.Text) Then –MsgBox(“You entered: “ & txtData.Text, MsgBoxStyle.Information, “Data is Valid”) Else –MsgBox(“A numeric value is required. Please try again.”, MsgBoxStyle.Critical, “Invalid Data”) End If

IsNumeric Examples ExpressionReturn Value “123”True “123.01”True “$1000”False “Zero”False “$100,000”False “123 Dollars”False

Data Validation Valid Range If txtData.Text < 160 Then –MsgBox(“You entered: “ & txtData.Text, MsgBoxStyle.Information, “Data is Valid”) Else –MsgBox(“Vacation hours may not exceed 160 per year.”, MsgBoxStyle.Critical, “Invalid Data”) End If

Combining Data Validation If IsNumeric(txtData.Text) Then –If txtData.Text < 160 Then MsgBox(“You entered: “ & txtData.Text, MsgBoxStyle.Information, “Data is Valid”) –Else MsgBox(“Vacation hours may not exceed 160 per year.”, MsgBoxStyle.Critical, “Invalid Data”) –End If Else MsgBox(“A numeric value is required. Please try again.”, MsgBoxStyle.Critical, “Invalid Data”) End If

String Comparisons Database applications use string comparisons to validate input and to sort information. The order of string data is determined by each character’s ASCII value. ASCII (American Standard Code for Information Interchange) is a standard designation of characters and symbols.

String Comparisons String comparisons are made from left to right one character pair at a time. The comparison is terminated when a character is unequal. “Browning” compared to “Brower” The first four pairs are equal. The fifth pair is unequal (n and e).

String Comparisons Value 1ASCII Value Value 2ASCII Value Value 1 > Value 2 Z122A65True False A65?63True Missouri79Mississippi73True False

UCase and LCase Functions Character Case is very important in string comparisons. Upper case letters are < lower case letters. Use LCase or UCase so you do not have to validate all possible user inputs.

Data Validation Specific Input If UCase(txtDept.Text) = “ACCT” Then ElseIf UCase(txtDept.Text) = “ECO” Then Else End If

Logical Operators And – If both conditions are True the result is True. Or – If either condition is True the result is True. Not – The condition is reversed. True becomes False, False becomes True.

Logical If Example In order to qualify for a bonus, an employee must be employed for at least 12 months and earn at least $25,000 annually.

Logical If Example If intMonthsEmployed >= 12 AND decSalary >= Then –Msgbox “You qualify for the employee bonus.” Else –Msgbox “You are not eligible for a bonus.” End If

Logical If Example An employee may qualify for a bonus, when been employed for 18 months or when he earns $25,000 annually.

Logical If Example If intMonthsEmployed >= 18 OR decSalary >= Then –Msgbox “You qualify for the employee bonus.” Else –Msgbox “You are not eligible for a bonus.” End If

Select Case Structure Used when a single expression is tested for multiple values. A Case is an individual condition. Select Case expression Case expressionlist End Select

Select Case Example Bonus is a percentage of salary depending on their performance rating. RatingBonus % % 1-35% 0 0%

Select Case Example Select Case intRating –Case < 1 sngBonusRate = 0 –Case 1 To 3 sngBonusRate =.05 –Case 4 To 7 sngBonusRate =.075 –Case 8 To 10 sngBonusRate =.1 End Select

Select Case Example

Radio Button CheckChanged Event Private mintRdbIndex as Integer Private Sub rdbLowSalary_CheckChanged () –mintRdbIndex = 0 End Sub Private Sub rdbHighSalary_CheckChanged () –mintRdbIndex = 3 End Sub

Select Case Example Select Case mintRdbIndex –Case 0 lblResult.Text = “Your salary is less than $20,000.” –Case 1 lblResult.Text = “Your salary is between $20,000 and $40,000.” –Case 2 lblResult.Text = “Your salary is between $41,000 and $60,000.” –Case 3 lblResult.Text = “Your salary is greater than $60,000.” End Select

Loan Payment Application

Mail Order Shipping Costs