Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Processing Decisions Chapter 3. If…Then…Else… Statements If decSalesAmount > 1000 Then sngTaxRate =.05 Else sngTaxRate =.07 End If."— Presentation transcript:

1 Processing Decisions Chapter 3

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

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

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

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

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

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

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

9 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

10 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.

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

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

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

14 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.

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

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

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

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

19 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

20 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.

21 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.

22 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.

23

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

25 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

26 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

27 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)

28 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

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

30 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

31 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

32 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.

33 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).

34 String Comparisons Value 1ASCII Value Value 2ASCII Value Value 1 > Value 2 Z122A65True +14345False A65?63True Missouri79Mississippi73True 100499857False

35 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.

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

37 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.

38 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.

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

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

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

42 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

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

44 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

45 Select Case Example

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

47 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

48 Loan Payment Application

49 Mail Order Shipping Costs


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

Similar presentations


Ads by Google