Export (0) Print
Expand All

Hello World in Visual Basic

.NET Framework 1.1

Finally, here is how Hello World looks in Visual Basic:

Listing 1. Hello World in Visual Basic (HelloVB.vb)

' Allow easy reference to the System namespace classes.
Imports System

' This module houses the application's entry point.
Public Module modmain
   ' Main is the application's entry point.
   Sub Main()
     ' Write text to the console.
     Console.WriteLine ("Hello World using Visual Basic!")
   End Sub
End Module

This code is almost the same as that for Visual C#. The syntax for accessing the core library is new — like with Visual C#, you specify the namespace rather than the file name:

Imports System

Other than that, there is not much else to say. The line that writes the output is almost the same as that for the other languages, especially now that Visual Basic requires parentheses around the method parameter. Of course, Visual Basic does not require using semicolons to terminate statements:

Console.WriteLine("Hello World using Visual Basic!")

The command line for compiling the program is the following:

vbc.exe /t:exe /debug+ /optionstrict+ /out:.\HelloVB.exe HelloVB.vb

In the previous line, /out specifies the output file, and /t indicates the target type. Executing the sample batch file containing this command line yields the following:

C:\...\HelloWorld\vb>build

C:\...\HelloWorld\vb> vbc.exe /t:exe /debug+ /optionstrict+ /out:.\HelloVB.exe HelloVB.vb
Microsoft (R) Visual Basic Compiler Version ...
for Microsoft (R) .NET CLR ...
Copyright (C) Microsoft Corp 2001. All rights reserved.

Executing the resulting executable file produces the following:

C:\...\HelloWorld\vb>hellovb
Hello World using Visual Basic!

See Also

Writing Simple .NET Components | Clients for the Simple Components | Summary of Development Tutorial | Appendix A: Tools for Exploring Namespaces

Show:
© 2014 Microsoft