2.1 What's in a Program?
A program consists of English-language instructions called
. The syntax for these instructions is
Each instruction has a semantic meaning that expresses what it is you are trying to accomplish. Although you must follow the syntax, the semantics of the language are far more important in developing effective object-oriented programs. This book will provide insight into both the syntax and the semantics of good VB.NET programs.
You will save the source code you write in a text file. You can write this source code file using any simple text editor (such as Notepad), or you can use the Visual Studio .NET Integrated Development Environment (IDE). Visual Studio .NET is described in Chapter 4.
Once you write your program, you compile it using the VB.NET compiler. The end result of compiling the program is an application.
2.2 Your First Program: Hello World
In this chapter, you will create a very simple application that does nothing more than display the words "Hello World" to your monitor. This basic console application is the traditional first program for learning any new language; it
Once you write your "Hello World" program and compile it, this chapter will provide a
As explained earlier, you can create VB.NET programs with any text editor. You can, for example, create each of the three programs shown previously (in Figure 2-1, Figure 2-2, and Figure 2-3) with Notepad. To
Begin by opening Notepad and typing in the program exactly as shown in Example 2-1.
Example 2-1. Hello World in Notepad
Module HelloWorld ' every console app starts with Main Sub Main( ) System.Console.WriteLine("Hello world!") End Sub End Module
That is the entire program. Save it to your disk as a file called helloworld.vb .
We'll examine this program in some detail in just a moment. First, however, it must be compiled.
2.2.1 The Compiler
Once you save your program to disk, you must compile the code to create your application. Compiling your source code means running a compiler and passing in the source code file. You run the compiler by opening a command prompt (DOS box) and entering the program
The job of the compiler is to
Microsoft provides a command window (through Visual Studio .NET) with the correct environment
Start -> Programs -> Microsoft Visual Studio .NET -> Visual Studio.NET Tools -> Visual Studio .NET Command Prompt
Then navigate to the directory in which you created your code file and enter the following command:
The Microsoft VB.NET compiler compiles your code; when you display the directory you'll find the compiler has produced an executable file called helloworld.exe . Type helloworld at the command prompt, and your program will execute, as shown in Figure 2-4.
Figure 2-4. Compiling and running Hello World
Presto! You are a VB.NET programmer. That's it, close the book, you've done it. Okay, don't close the book; there are details to examine, but take a moment to congratulate yourself. Have a cookie.
Granted, the program you created is one of the simplest VB.NET programs imaginable, but it is a complete VB.NET program, and it can be used to examine many of the elements common to VB.NET programs.