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.

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

1 ' Fig. 3.1: Welcome1.vb<br />

2 ' Simple <strong>Visual</strong> <strong>Basic</strong> program.<br />

3<br />

4 Module modFirstWelcome<br />

5<br />

6 Sub Main()<br />

7 Console.WriteLine("Welcome <strong>to</strong> <strong>Visual</strong> <strong>Basic</strong>!")<br />

8 End Sub ' Main<br />

9<br />

10 End Module ' modFirstWelcome<br />

Welcome <strong>to</strong> <strong>Visual</strong> <strong>Basic</strong>!<br />

Fig. Fig. 3.1 3.1 Simple <strong>Visual</strong> <strong>Basic</strong> program .<br />

“end-of-line comments”). The <strong>Visual</strong> <strong>Basic</strong> compiler ignores comments, which means that<br />

comments do not cause the computer <strong>to</strong> perform any actions when the program is run. The<br />

comment in line 1 simply indicates the figure number and file name for this program. Line<br />

2 provides a brief description of the program. By convention, every program in this book<br />

begins in this manner—you can write anything you want in a comment. In this case, the file<br />

is named Welcome1.vb. Recall that .vb is the file extension for <strong>Visual</strong> <strong>Basic</strong> files.<br />

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

Every program should begin with one or more comments describing the program’s purpose. 3.1<br />

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

Comments written at the end of a line should be preceded by one or more spaces <strong>to</strong> enhance<br />

program readability. 3.2<br />

Lines 4–10 define our first module (these lines collectively are called a module definition).<br />

<strong>Visual</strong> <strong>Basic</strong> console applications consist of pieces called modules, which are logical<br />

groupings of procedures that simplify program organization. Procedures perform tasks and<br />

can return information when the tasks are completed. Every console application in <strong>Visual</strong><br />

<strong>Basic</strong> consists of at least one module definition and one procedure. In Chapter 6, Procedures,<br />

we discuss modules and procedures in detail.<br />

The word Module is an example of a keyword (or reserved word). Keywords are<br />

reserved for use by <strong>Visual</strong> <strong>Basic</strong> (a complete list of <strong>Visual</strong> <strong>Basic</strong> keywords is presented in<br />

the next chapter). The name of the Module (i.e., modFirstWelcome) is known as an<br />

identifier, which is a series of characters consisting of letters, digits, and underscores ( _ ).<br />

Identifiers cannot begin with a digit and cannot contain spaces. Examples of valid identifiers<br />

are value1, xy_coordinate, __<strong>to</strong>tal and cmdExit. The name 7Welcome<br />

is not a valid identifier because it begins with a digit, and the name input field is not<br />

a valid identifier because it contains a space.<br />

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

Begin each module identifier with mod <strong>to</strong> make modules easier <strong>to</strong> identify. 3.3

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

Saved successfully!

Ooh no, something went wrong!