Visual Basic 'NET BASICS - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Visual Basic 'NET BASICS

Description:

Use the exponentiation operator to raise numbers to a power. Describe the ... Handle run-time errors using the Try ... exponentiation is the caret ... – PowerPoint PPT presentation

Number of Views:104
Avg rating:3.0/5.0
Slides: 15
Provided by: stephenc9
Category:
Tags: basics | net | basic | caret | visual

less

Transcript and Presenter's Notes

Title: Visual Basic 'NET BASICS


1
Visual Basic .NET BASICS
  • Lesson 5
  • Exponentiation, Order of Operations, and Error
    Handling

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

3
Objectives (continued)
  • Handle run-time errors using the Try/Catch
    structure.
  • Display messages using the MsgBox function.
  • Control program flow using the Exit Sub
    statement.

4
Exponentiation
  • Exponentiation is the process of raising a number
    to a power.
  • The symbol that represents exponentiation is the
    caret ().
  • The operator raises the number to the left of the
    operator to the power that appears on the right
    of the operator.

5
Order of Operations
  • From your math classes, you may recall the rules
    called the order of operations.
  • Visual Basic .NET uses the same set of rules for
    its calculations.
  • Visual Basic .NET allows you to use parentheses
    to override the order of operations.

6
Using the Visible Property to Enhance Output
  • You have used the Visible property to make an
    image appear and disappear.
  • Another example of a useful application of the
    Visible property is preventing labels from
    appearing until you are ready for the user to see
    the label.
  • By initially setting the Visible property to
    False, the output will remain invisible until you
    make the labels visible in the code.

7
Using Comments
  • The Properties window allows you to easily alter
    the properties of objects.
  • Two of the most important properties of a form
    are the Text and Name properties.
  • The Text property specifies the text that appears
    in the title bar.
  • The Name property names the object for coding.

8
Handling Run-Time Errors
  • Users will enter all kinds of unexpected data or
    fail to enter required data.
  • These are exceptions or run-time errors.
  • Run-time errors are not detected at the time the
    program is compiled because the error is caused
    by conditions that do not exist until the program
    is running.
  • When a run-time error occurs, the system throws
    an exception.

9
Trapping Run-Time Errors with the Try/Catch
Structure
  • Visual Basic .NET allows you to write code that
    will executed when a run-time error occurs.
  • To specify what code will execute when an error
    occurs, you must turn on error trapping.
  • To turn on error trapping, place a Try statement
    above the code that may generate a run-time
    error.
  • The code that will be executed if an error occurs
    is often called an error handler.

10
Using MsgBox
  • One of the easiest ways to display a message of
    your own, such as an error message, is to use the
    MsgBox function.
  • The MsgBox function causes a dialog box to pop
    up, displaying a message that you specify.

11
Using End 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.
  • The procedure will end when the flow of execution
    reaches the Exit Sub statement and can be placed
    anywhere in the subroutine.
  • This allows the programmer to exit the subroutine
    for different reasons.

12
Summary
  • The exponential operator () raises a number to a
    power.
  • The rules that dictate the order that math
    operators are applied in a formula are called the
    order of operations.
  • Parentheses can be used to override the order of
    operations.
  • The Visible property can be used to hide a label
    until you are ready for the user to see it.

13
Summary (continued)
  • The apostrophe is used to add comments to Visual
    Basic. NET code. Comments allow you to keep track
    of changes in code and explain the purpose of
    code. Comments are often called internal
    documentation.
  • Errors that occur while a program is running are
    called run-time errors or exceptions. Visual
    Basic. NET allows you to trap errors, using
    Try/Catch, and execute special code that you
    specify to handle the error.

14
Summary (continued)
  • The MsgBox function pops up a dialog box,
    delivering a message to the user.
  • When you detect errors that cannot be completely
    handled, you should send the user a message and
    use the Exit Sub to end the event procedure
    before the error can cause additional problems.
Write a Comment
User Comments (0)
About PowerShow.com