Microsoft visual basic 2005 basics
Download
1 / 28

Lesson 6 - PowerPoint PPT Presentation


  • 259 Views
  • Uploaded on

Lesson 6 PP

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Lesson 6' - bonoli01


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Microsoft visual basic 2005 basics l.jpg

Microsoft Visual Basic 2005 BASICS

Lesson 6

Exponentiation, Order of Operations, and Error Handling


Objectives l.jpg
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.

Microsoft Visual Basic 2005 BASICS


Objectives cont l.jpg
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.

Microsoft Visual Basic 2005 BASICS


Exponentiation l.jpg
Exponentiation

  • Exponentiation

    • Process of raising a number to a power

    • Represented by the caret (^)

  • Operator raises the number to the left of the operator to the power that appears on the right of the operator

Microsoft Visual Basic 2005 BASICS


Order of operations l.jpg
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

Microsoft Visual Basic 2005 BASICS


Order of operations cont l.jpg
Order of Operations (cont.)

Microsoft Visual Basic 2005 BASICS


Order of operations cont7 l.jpg
Order of Operations (cont.)

  • Basic order of operations

    • Exponentiation

    • Unary plus and minus

    • Multiplication, division, integer division, modulus

    • Addition and subtraction

Microsoft Visual Basic 2005 BASICS


Order of operations cont8 l.jpg
Order of Operations (cont.)

Microsoft Visual Basic 2005 BASICS


Order of operations cont9 l.jpg
Order of Operations (cont.)

Microsoft Visual Basic 2005 BASICS


Order of operations cont10 l.jpg
Order of Operations (cont.)

Microsoft Visual Basic 2005 BASICS


Using the visible property to enhance output l.jpg
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

Microsoft Visual Basic 2005 BASICS


Using the visible property to enhance output cont l.jpg
Using the Visible Property to Enhance Output (cont.)

Microsoft Visual Basic 2005 BASICS


Using comments l.jpg
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

Microsoft Visual Basic 2005 BASICS


Using comments cont l.jpg
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.

Microsoft Visual Basic 2005 BASICS


Handling run time errors l.jpg
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.

Microsoft Visual Basic 2005 BASICS


Handling run time errors cont l.jpg
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.

Microsoft Visual Basic 2005 BASICS


Handling run time errors cont17 l.jpg
Handling Run-Time Errors (cont.)

Microsoft Visual Basic 2005 BASICS


Trapping run time errors with the try catch structure l.jpg
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.

Microsoft Visual Basic 2005 BASICS


Trapping run time errors with the try catch structure cont l.jpg
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

Microsoft Visual Basic 2005 BASICS


Trapping run time errors with the try catch structure cont20 l.jpg
Trapping Run-Time Errors with the Try/Catch Structure (cont.)

Microsoft Visual Basic 2005 BASICS


Using msgbox l.jpg
Using MsgBox (cont.)

  • 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

Microsoft Visual Basic 2005 BASICS


Using msgbox cont l.jpg
Using MsgBox (cont.) (cont.)

Microsoft Visual Basic 2005 BASICS


Using exit sub to exit a subroutine l.jpg
Using Exit Sub to Exit a Subroutine (cont.)

  • 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

Microsoft Visual Basic 2005 BASICS


Using exit sub to exit a subroutine cont l.jpg
Using Exit Sub to Exit a Subroutine (cont.) (cont.)

Microsoft Visual Basic 2005 BASICS


Summary l.jpg
Summary (cont.)

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

Microsoft Visual Basic 2005 BASICS


Summary cont l.jpg
Summary (cont.) (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.

Microsoft Visual Basic 2005 BASICS


Summary cont27 l.jpg
Summary (cont.) (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.

Microsoft Visual Basic 2005 BASICS


Summary cont28 l.jpg
Summary (cont.) (cont.)

  • The MsgBoxfunction 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.

Microsoft Visual Basic 2005 BASICS


ad