30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

82 Introduction <strong>to</strong> <strong>Visual</strong> <strong>Basic</strong> <strong>Program</strong>ming Chapter 3<br />

1000 = 1000<br />

1000 = 1000<br />

Notice the indentation in the If/Then statements throughout the program. Such<br />

indentation enhances program readability.<br />

Good <strong>Program</strong>ming Practice 3.14<br />

Indent the statement in the body of an If/Then structure <strong>to</strong> emphasize the body of the structure<br />

and <strong>to</strong> enhance program readability. 3.14<br />

Common <strong>Program</strong>ming Error 3.3<br />

Omission of the Then keyword in an If/Then structure is a syntax error. 3.3<br />

The table in Fig. 3.20 shows the precedence of the opera<strong>to</strong>rs introduced in this chapter.<br />

The opera<strong>to</strong>rs are displayed from <strong>to</strong>p <strong>to</strong> bot<strong>to</strong>m in decreasing order of precedence. All opera<strong>to</strong>rs<br />

in <strong>Visual</strong> <strong>Basic</strong> .<strong>NET</strong> associate from left <strong>to</strong> right.<br />

Testing and Debugging Tip 3.3<br />

When uncertain about the order of evaluation in a complex expression, use parentheses <strong>to</strong><br />

force the order, as you would do in an algebraic expression. Doing so can help avoid subtle<br />

bugs. 3.3<br />

3.7 Using a Dialog <strong>to</strong> Display a Message<br />

Although the programs discussed thus far display output in the command window, most <strong>Visual</strong><br />

<strong>Basic</strong> programs use dialogs <strong>to</strong> display output. Dialogs are windows that typically display<br />

messages <strong>to</strong> the user. <strong>Visual</strong> <strong>Basic</strong> provides class MessageBox for creating dialogs.<br />

The program in Fig. 3.21 uses a dialog <strong>to</strong> display the square root of 2.<br />

In this example, we present a program that contains a simple GUI (i.e., the dialog). The<br />

.<strong>NET</strong> Framework Class Library (FCL) contains a rich collection of classes that can be used<br />

<strong>to</strong> construct GUIs. FCL classes are grouped by functionality in<strong>to</strong> namespaces. Line 4 is an<br />

Imports statement that indicates we are using the features provided by the<br />

System.Windows.Forms namespace. For example, System.Windows.Forms<br />

contains windows-related classes (i.e., forms and dialogs). We discuss this namespace in<br />

detail after we discuss the code in this example.<br />

Opera<strong>to</strong>rs Type<br />

() parentheses<br />

^ exponentiation<br />

* / multiplicative<br />

\ Integer division<br />

Mod modulus<br />

Fig. Fig. 3.20 3.20 Precedence and associativity of opera<strong>to</strong>rs introduced in this chapter<br />

(part 1 of 2).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!