Compiling Your First Program


If you tried to compile your program now, you would get an error message stating that Sub Main is not found. This error message means that Visual Basic .NET doesn't know where to start executing the program. The reason Visual Basic .NET needs this information is because you can write programs that have more than just one form in them. Therefore, even though your simple program has only one form, Visual Basic .NET still wants you to specify which form should be used to begin program execution.

To supply the missing information, select View, Solution Explorer. (Note that Ctrl+R also activates the Solution Explorer menu option.) If you have done this correctly, your screen should look like Figure 2.13.

Figure 2.13. The Solution Explorer window.

graphics/02fig13.jpg

Notice that the Properties window has been pushed down, and the Solution Explorer window appears near the top-right portion of the screen. Because you need to tell Visual Basic .NET where to start your program, you need to click the second line, FirstProgram1 . When you do this, the five icons you see directly below the Solution Explorer title bar collapses to three icons, as shown in Figure 2.14.

Figure 2.14. The Properties ToolTip for FirstProgram1 .

graphics/02fig14.jpg

If you click the rightmost icon, which is the Properties icon for FirstProgram1 , the display changes to that shown in Figure 2.15.

Figure 2.15. Setting the FirstProgram1 startup object.

graphics/02fig15.jpg

Near the middle of the form is a field labeled Startup Object. If you click the down-arrow at the right edge of the field, your display should look like that shown in Figure 2.15. Visual Basic .NET is asking you to select the object that should be used to start your program. Because you have only one form, you should select frmFirstProgram as the startup object and then click the OK button. The screen should revert to the one shown in Figure 2.14.

Now select Build, Build Solution. Visual Basic .NET compiles your program, and you should see a display similar to the one shown in Figure 2.16.

Figure 2.16. The display after a successful compilation.

graphics/02fig16.jpg

As you can see in the Build window, near the bottom of the display screen, the build of your program is successful. You can now run the program.



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