Ppt lesson 06


Published on

Published in: Technology, News & Politics
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Ppt lesson 06

  1. 1. Microsoft Visual Basic 2005 BASICS Lesson 6 Exponentiation, Order of Operations, and Error Handling
  2. 2. Objectives <ul><li>Use the exponentiation operator to raise numbers to a power. </li></ul><ul><li>Describe the order of operations. </li></ul><ul><li>Use the Visible property to enhance output. </li></ul><ul><li>Describe the purpose of comments in programs. </li></ul>
  3. 3. Objectives (cont.) <ul><li>Handle run-time errors using the Try/Catch structure. </li></ul><ul><li>Display messages using the MsgBox function. </li></ul><ul><li>Control program flow using the Exit Sub statement. </li></ul>
  4. 4. Exponentiation <ul><li>Exponentiation </li></ul><ul><ul><li>Process of raising a number to a power </li></ul></ul><ul><ul><li>Represented by the caret (^) </li></ul></ul><ul><li>Operator raises the number to the left of the operator t o the power that appears on the right of the operator </li></ul>
  5. 5. Order of Operations <ul><li>From your math classes </li></ul><ul><ul><li>Recall the rules called the order of operations </li></ul></ul><ul><li>Visual Basic </li></ul><ul><ul><li>Uses the same set of rules for its calculations </li></ul></ul><ul><li>Parentheses </li></ul><ul><ul><li>Override the order of operations </li></ul></ul>
  6. 6. Order of Operations (cont.)
  7. 7. Order of Operations (cont.) <ul><li>Basic order of operations </li></ul><ul><ul><li>Exponentiation </li></ul></ul><ul><ul><li>Unary plus and minus </li></ul></ul><ul><ul><li>Multiplication, division, integer division, modulus </li></ul></ul><ul><ul><li>Addition and subtraction </li></ul></ul>
  8. 8. Order of Operations (cont.)
  9. 9. Order of Operations (cont.)
  10. 10. Order of Operations (cont.)
  11. 11. Using the Visible Property to Enhance Output <ul><li>Visible property </li></ul><ul><ul><li>Prevents labels from appearing until you are ready for the user to see the label </li></ul></ul><ul><li>By initially setting the Visible property to False </li></ul><ul><ul><li>Output will remain invisible until you make the labels visible in the code </li></ul></ul>
  12. 12. Using the Visible Property to Enhance Output (cont.)
  13. 13. Using Comments <ul><li>Use an apostrophe to create comments. </li></ul><ul><ul><li>Comments can appear on their own lines. </li></ul></ul><ul><li>Use comments to </li></ul><ul><ul><li>Explain the purpose of a program </li></ul></ul><ul><ul><li>Keep notes regarding changes to the source code </li></ul></ul><ul><ul><li>Store the names of programmers for future reference </li></ul></ul>
  14. 14. Using Comments (cont.) <ul><li>Use comments to (cont.) </li></ul><ul><ul><li>Explain the parts of your program </li></ul></ul><ul><ul><li>Temporarily remove lines from the program during testing </li></ul></ul><ul><li>Comments added to programs are often called internal documentation. </li></ul>
  15. 15. Handling Run-Time Errors <ul><li>Exceptions or run-time errors </li></ul><ul><ul><li>Errors that occur when the program is running </li></ul></ul><ul><li>Run-time errors are not detected at the time the program is compiled. </li></ul>
  16. 16. Handling Run-Time Errors (cont.) <ul><li>When a run-time error occurs </li></ul><ul><ul><li>The system throws an exception. </li></ul></ul><ul><ul><ul><li>A signal is sent to the program that needs to be handled or caught. </li></ul></ul></ul>
  17. 17. Handling Run-Time Errors (cont.)
  18. 18. Trapping Run-Time Errors with the Try/Catch Structure <ul><li>Write code that will execute when a run-time error occurs. </li></ul><ul><ul><li>You must turn on error trapping. </li></ul></ul><ul><ul><li>Place a Try statement above the code that may generate a run-time error. </li></ul></ul><ul><li>Code is often called an error handler. </li></ul>
  19. 19. Trapping Run-Time Errors with the Try/Catch Structure (cont.) <ul><li>Error trapping </li></ul><ul><ul><li>Process of interrupting the normal chain of events and replacing that chain with your own code </li></ul></ul>
  20. 20. Trapping Run-Time Errors with the Try/Catch Structure (cont.)
  21. 21. Using MsgBox <ul><li>MsgBox function </li></ul><ul><ul><li>One of the easiest ways to display a message of your own </li></ul></ul><ul><ul><ul><li>Such as an error message </li></ul></ul></ul><ul><ul><li>Causes a dialog box to pop up </li></ul></ul><ul><ul><ul><li>Displays a message that you specify </li></ul></ul></ul>
  22. 22. Using MsgBox (cont.)
  23. 23. Using Exit Sub to Exit a Subroutine <ul><li>The Exit Sub statement </li></ul><ul><ul><li>Forces the event procedure to end </li></ul></ul><ul><ul><ul><li>Regardless of whether there is more code in the procedure </li></ul></ul></ul><ul><ul><li>Can be placed anywhere in the subroutine </li></ul></ul><ul><ul><li>Allows the programmer to exit the subroutine for different reasons </li></ul></ul>
  24. 24. Using Exit Sub to Exit a Subroutine (cont.)
  25. 25. Summary <ul><li>The exponential operator (^) raises a number to a power. </li></ul><ul><li>The rules that dictate the order in which math operators are applied in a formula are called the order of operations. </li></ul><ul><li>Parentheses can be used to override the order of operations. </li></ul>
  26. 26. Summary (cont.) <ul><li>The Visible property can be used to hide a label until you are ready for the user to see it. </li></ul><ul><li>The apostrophe is used to add comments to Visual Basic code. Comments allow you to keep track of changes and to explain the purpose of code. Comments are often called internal documentation. </li></ul>
  27. 27. Summary (cont.) <ul><li>Errors that occur while a program is running are called run-time errors or exceptions. </li></ul><ul><ul><li>Visual Basic allows you to trap errors, using Try/Catch , and execute special code that you specify to handle the error. </li></ul></ul>
  28. 28. Summary (cont.) <ul><li>The MsgBox function pops up a dialog box, delivering a message to the user. </li></ul><ul><li>When you detect errors that cannot be handled completely, send the user a message and use an Exit Sub statement to end the event procedure before the error can cause additional problems. </li></ul>