Running Your First Program


In order to execute the simple but complete Visual Basic .NET program you have created, you need to compile it. When you compile a program, you are changing the visual and textual state of the program that you see onscreen to a set of instructions that your computer can understand and execute. To compile a program, you select Build, Build Solution. You could also press Ctrl+Shift+B to cause the program to compile the program. Either method builds the program.

Building Versus Compiling

So why do we say compile the program, but Visual Basic .NET says it's going to build the program? Compiling a program only translates the part of the program that you wrote into executable instructions. To form a complete program, Visual Basic .NET splices a bunch of prewritten mini-programs and routines into the program that it needs in order to make everything work. (You will learn more details about all this in later chapters.) Although Visual Basic .NET does in fact compile a program during the build process, it also links in many other components and objects to create a fully functioning program. Therefore, Visual Basic .NET does compile the part of the program that you wrote, but your code is only a subpart of the build process that is necessary to make a complete Visual Basic .NET program.

Other Ways to Run a Program

Note that you can also compile, build, and run a program by selecting Debug, Start. Or you can simply press the F5 key. In either case, Visual Basic .NET automatically activates the Visual Basic .NET Debugger. The Visual Basic .NET debugger is a tool that is used to track down program errors (called bugs ) as the program executes. The debugger and the process of debugging a program are discussed in great detail in Chapter 19, "Error Processing and Debugging."

You can also run a program with a simple mouse click. Look closely just below the Help menu in Figure 1.29, and you should see the word Debug in a text box. Just to the left of that text box is a small, right-pointing blue triangle. If you click that triangle, the program immediately begins execution.

Regardless of the method you use to run a program (you should try all of them), the output of the program should look similar to that shown in Figure 1.30. To end program execution, click the X that you see near the upper-right side of the form. The program terminates, and you are returned to the IDE. Congratulations! You have successfully created, compiled, and run your first Visual Basic .NET program!

Figure 1.30. A sample program run.

graphics/01fig30.jpg



Visual Basic .NET. Primer Plus
Visual Basic .NET Primer Plus
ISBN: 0672324857
EAN: 2147483647
Year: 2003
Pages: 238
Authors: Jack Purdum

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net