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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

James Fenimore Cooper<br />

Outline<br />

3.1 Introduction<br />

3.2 Simple <strong>Program</strong>: Printing a Line of Text<br />

3.3 Another Simple <strong>Program</strong>: Adding Integers<br />

3.4 Memory Concepts<br />

3.5 Arithmetic<br />

3.6 Decision Making: Equality and Relational Opera<strong>to</strong>rs<br />

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

3.8 Internet and World Wide Web Resources<br />

Summary Terminology Self-Review Exercises Answers <strong>to</strong> Self-Review Exercises Exercises<br />

3.1 Introduction<br />

<strong>Visual</strong> <strong>Basic</strong> .<strong>NET</strong> enables a disciplined approach <strong>to</strong> computer-program design. In this<br />

chapter, we introduce <strong>Visual</strong> <strong>Basic</strong> programming and present examples that illustrate several<br />

important features of the language. To help readers better understand the examples in<br />

this and other chapters, program code is analyzed one line at a time. In this chapter, we introduce<br />

console applications—applications that contain only text output. There are several<br />

types of <strong>Visual</strong> <strong>Basic</strong> projects; the console application is one of the simplest types. Text<br />

output in a console application is displayed in a command window (also called a console<br />

window). On Microsoft Windows 95/98, the command window is called the MS-DOS<br />

prompt; on Microsoft Windows NT/2000/XP, the command window is called the command<br />

prompt. With a sophisticated language like <strong>Visual</strong> <strong>Basic</strong>, programmers can create programs<br />

that input and output information in a variety of ways, which we discuss throughout the<br />

book. For instance, in Chapter 2, we created a simple graphical user interface (GUI) for a<br />

Windows application, using visual programming techniques. Windows applications are<br />

discussed in greater detail in Chapters 4 and 5, Control Structures: Part 1 and Control Structures:<br />

Part 2, respectively. These chapters provide a more detailed introduction <strong>to</strong> program<br />

development in <strong>Visual</strong> <strong>Basic</strong>.<br />

3.2 Simple <strong>Program</strong>: Printing a Line of Text<br />

<strong>Visual</strong> <strong>Basic</strong> .<strong>NET</strong> uses some notations that might appear strange <strong>to</strong> nonprogrammers. To<br />

explain these notations, we begin by considering a simple program (Fig. 3.1) that displays<br />

a line of text. When this program is run, the output appears in a command window.<br />

This program illustrates several important <strong>Visual</strong> <strong>Basic</strong> features. For the reader’s convenience,<br />

all program listings in this text include line numbers—these line numbers are not<br />

part of <strong>Visual</strong> <strong>Basic</strong> programs. In addition, each program is followed by one or more windows<br />

showing the program’s output.<br />

Line 1 begins with a single-quote character (') which indicates that the remainder of<br />

the line is a comment. <strong>Program</strong>mers insert comments in a program, or code listing, <strong>to</strong><br />

improve the readability of their code. Comments can be placed either on their own line (we<br />

call these “full-line comments”) or at the end of a line of <strong>Visual</strong> <strong>Basic</strong> code (we call these

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

Saved successfully!

Ooh no, something went wrong!