Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 5 Visual Basic Variables and Formulas, and the .NET Framework 143



  1. Click the Start Debugging button on the Standard toolbar to run the program.

  2. Click the Show Constant button.


The Pi constant appears in the label box, as shown here:


  1. Click the Quit button to stop the program.


Constants are useful in program code, especially in involved mathematical formulas,
such as Area = πr^2. The next section describes how you can use operators and variables
to write similar formulas.

Working with Visual Basic Operators


A formula is a statement that combines numbers, variables, operators, and keywords to create
a new value. Visual Basic contains several language elements designed for use in formulas. In
this section, you’ll practice working with arithmetic (or mathematical) operators, the symbols
used to tie together the parts of a formula. With a few exceptions, the arithmetic symbols
you’ll use are the ones you use in everyday life, and their operations are fairly intuitive. You’ll
see each operator demonstrated in the following exercises.

Visual Basic includes the arithmetic operators listed in Table 5-2.

TABLE 5-2 Arithmetic Operators
Operator Description
+ Addition


  • Subtraction



  • Multiplication
    / Division
    \ Integer (whole number) division
    Mod Remainder division
    ^ Exponentiation (raising to a power)
    & String concatenation (combination)

Free download pdf