O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Program Structure

VB.NET, unlike previous versions of Visual Basic, is fully object-oriented. Also unlike previous versions, VB.NET is fully integrated with its underlying platform, the .NET Framework and the .NET Common Language Runtime. As shown in this chapter, these two factors, perhaps more than any others, influence the structure of a VB.NET program.

Getting a VB Program to Run

Any Visual Basic executable — i.e., a Windows Forms or Windows console application — has a single application-level entry point, a subroutine named Main. Main must be a method of the executed class.

Tip

The web applications (either ASP.NET applications or web service applications) that you develop with Visual Studio are not executables. They exist as dynamic link libraries (DLLs) in the system’s disk storage. ASP.NET applications may also rely on just-in-time compilation and be resident solely in memory.

Main must not only exist, it must also be:

A public routine

In VB 6, Main could be either public or private. In VB.NET, it must be public to be visible as an entry point.

A static or shared routine

Its declaration must include the Shared keyword. A single Main method must be shared by all application instances; it cannot be an instance method. Thus, all methods called by Main must also be static (or shared) methods; a shared method is unable to invoke an instance method.

Tip

This section focuses on executable programs. These programs exclude code libraries, as well as ASP.NET applications and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required