An Example Visual Basic .NET Program
The first program to write is the same for all languages: Print the words hello, world
—Brian W. Kernighan and Dennis M. Ritchie, The C Programming Language
It has become a tradition for programming books to begin with a hello, world example. The idea is that entering and running a program—any program—may be the biggest hurdle faced by experienced programmers approaching a new platform or language. Without overcoming this hurdle, nothing else can follow. This chapter contains three such examples: one that creates a console application, one that creates a GUI application, and one that creates a browser-based application. Each example stands alone and can be run as is. The console and GUI applications can both be compiled from the command line (yes, Visual Basic .NET has a command-line compiler!). The browser-based application requires a computer running Internet Information Server (IIS).
hello, world
This is the world’s favorite programming example, translated to Visual Basic .NET:
Imports System
Public Module Hello
Public Sub Main( )
Console.WriteLine("hello, world")
End Sub
End ModuleThis version of hello, world is a
console application --
it
displays its output in a Windows command-prompt window. To compile
this program, enter it using any text editor, such as Windows’s
Notepad, save it in a file whose name ends with
.vb, such as Hello.vb, and
compile it from the Windows command line with this command:
vbc Hello.vb
The command vbc invokes ...