144 Part II Programming Fundamentals
Basic Math: The +, –, *, and / Operators
The operators for addition, subtraction, multiplication, and division are pretty straightforward
and can be used in any formula where numbers or numeric variables are used. The following
exercise demonstrates how you can use them in a program.
Work with basic operators
- On the File menu, click Open Project.
- Open the Basic Math project in the C:\Vb10sbs\Chap05\Basic Math folder.
- If the project’s form isn’t visible, click Form1 .vb in Solution Explorer, and then click
the View Designer button.
The Basic Math form opens in the Designer. The Basic Math program demonstrates
how the addition, subtraction, multiplication, and division operators work with numbers
you type. It also demonstrates how you can use text box, radio button, and button
objects to process user input in a program. - Click the Start Debugging button on the Standard toolbar.
The Basic Math program runs in the IDE. The program displays two text boxes in which
you enter numeric values, a group of operator radio buttons, a box that displays results,
and two button objects (Calculate and Quit).
- Type 100 in the Variable 1 text box, and then press TAB.
The insertion point, or focus, moves to the second text box.
- Type 17 in the Variable 2 text box.
You can now apply any of the mathematical operators to the values in the text boxes.
- Click the Addition radio button, and then click the Calculate button.
The operator is applied to the two values, and the number 117 appears in the Result
box, as shown in the following screen shot.