Finally, here is how "Hello World" looks in Visual Basic:
Listing 3. "Hello World" in VB (HelloVB.vb)
' Allow easy reference System namespace classes Imports System ' Module houses the application's entry point Public Module modmain ' "Main" is 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 for C#. The syntax for accessing the core library is new, where – like with C# – we specify the namespace rather than the filename:
Imports System
Other than that, there's not much else to say. The output line is almost the same as for the other languages, especially now that VB requires parentheses around the method parameter. Of course, VB does not require using semi-colons to terminate statements:
Console.WriteLine "Hello World using Visual Basic!"
The command line for compiling the sample Hello World VB program is:
vbc HelloVB.vb /out:HelloVB.exe /t:exe
where /o
specifies the output file and /t
indicates the target type. Executing the sample batch file containing this command-line yields:
C:\…\HelloWorld\vb>build C:\…\HelloWorld\vb>vbc HelloVB.vb /out:HelloVB.exe /t:exe Microsoft (R) Visual Basic Compiler Version …[NGWS runtime version …] Copyright (C) Microsoft Corp 2000. All rights reserved.
And executing the resulting executable produces:
C:\…\HelloWorld\vb>hellovb Hello World using Visual Basic!