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

Ppt lesson 06

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