1 / 10

Decisions Nested on True Branch

Decisions Nested on True Branch. False. True. Condition1 ?. Steps ABC. Steps to process if condition 1 is false. False. True. Condition2 ?. Steps to process if condition1 is true and condition2 is false. Steps to process if both condition1 and condition2 are true. Steps XYZ.

faunus
Download Presentation

Decisions Nested on True Branch

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Decisions Nested on True Branch False True Condition1 ? Steps ABC Steps to process if condition 1 is false False True Condition2 ? Steps to process if condition1 is true and condition2 is false Steps to process if both condition1 and condition2 are true Steps XYZ Note the indentation If condition1 Then Statements for steps ABC If condition2 Then statement(s) for condition1 and condition2 true Else statement(s) for condition1 true and condition2 false End If Statements for steps XYZ Else statement(s) for condition1 false End If

  2. Decisions Nested on False Branch False True Condition1 ? Steps ABC Steps to process False True if condition1 is Condition2 ? true Steps to process Steps to process if both condition1 and condition2 are false if condition1 is false and condition2 is true Steps XYZ Note the indentation If condition1 Then statement(s) for condition1 true Else Statements for steps ABC If condition2 Then statement(s) for condition1 false and condition2 true Else statement(s) for condition1 and condition2 false End If Statements for steps XYZ End If

  3. Nested Decisions on False (ElseIf) False True Condition1 ? Steps to process False True if condition1 is Condition2 ? true Steps to process if both condition1 and condition2 are false Steps to process if condition1 is false and condition2 is true False branch contains a complete decision structure and no intervening steps before and after the decision If condition1 Then statement(s) for condition1 true ElseIf condition2 Then statement(s) for condition1 false and condition2 true Else statement(s) for both condition1 and condition2 false End If Note the indentation

  4. Select Case: Special Case of Nested Decisions on False (ElseIf) Case expression Steps to process if cond1 True True cond1 False Steps to process if cond2 True True cond2 False Steps to process if condn True True condn Steps to process if condn False When every decision in nested if compares values against the same expression Select Case expression Case cond1 statement(s) for cond1 true Case cond2 statement(s) for cond1 false and cond2 true : Case condn statement(s) for cond1-condn-1 false and condn true Case Else statement(s) for al conditions false End Select Note the indentation

  5. Limitations of Data Validation • It can become quite difficult to handle every type of problem during data validation that could arise. • VB provides the option of including error handlers to augment or as an alternative to data validation processing. • Supplying too large of a value to a conversion function will trigger an overflow error. • During division operations, a zero divisor will trigger a division by zero run time error. • Passing the wrong type of data to a function or procedure will trigger a type mismatch error.

  6. VB’s Built-in Error Handling • What happens when errors occur in VB? • Number, source and description of VB’s Err object are updated • VB displays error message with above information • Program breaks or terminates

  7. Writing Error Handlers • Instruct VB to bypass its error handling • On Error Goto PgmLabelName • Bypass error handler if no errors triggered • Add Exit Sub after last line of procedure body and right before End Sub • Add Error Handler code between Exit Sub & End Sub • Add Error Handler label • PgmLabelName: • Add Error Handler code

  8. Error Handler Example 1 • Similar to VB’s built-in error handling • Important difference is that the program does not terminate execution Private Sub cmdCalc_Click() On Error GoTo HandleErrors ‘ override VB’s intrinsic error handling If DataVal Then ‘ do normal processing End If Exit Sub ‘ all done if it was the normal case HandleErrors: ‘ starting point of error handler Call MsgBox(Err.Number & “: “ & Err.Description, _ vbOkOnly+vbInformation) End Sub

  9. Error Handler Example 2 Private Sub cmdCalc_Click() On Error GoTo HandleErrors If DataVal Then ‘ do normal processing End If Exit Sub HandleErrors: If Err.Number = 6 Then Call MsgBox(“Overflow occurred in formula”, vbOkOnly+vbInformation) ElseIf Err.Number = 11 Then Call MsgBox(“Division by 0 not allowed”, vbOkOnly+vbInformation) ElseIf Err.Number = 13 Then Call MsgBox(“Check data type compatibility”, vbOkOnly+vbInformation) Else Call MsgBox(Err.Number & “: “ & Err.Description, vbOkOnly+vbInformation) End If End Sub

  10. Error Handler Example 3 Private Sub cmdCalc_Click() On Error GoTo HandleErrors If DataVal Then ‘ do normal processing End If Exit Sub HandleErrors: Select Case Err.Number Case 6 Then Call MsgBox(“Overflow occurred in formula”, vbOkOnly+vbInformation) Case 11 Call MsgBox(“Division by 0 not allowed”, vbOkOnly+vbInformation) Case 13 Call MsgBox(“Check data type compatibility”, vbOkOnly+vbInformation) Case Else Call MsgBox(Err.Number & “: “ & Err.Description, vbOkOnly+vbInformation) End Select End Sub

More Related