Next up, let's examine how to compile an application that makes use of types defined in an external .NET assembly. Speaking of which, just in case you are wondering how the VB 2008 compiler understood your reference to the System.Console type, recall from Chapter 1 that mscorlib.dll (the assembly that contains the System.Console type) is automatically referenced during the compilation process.
To illustrate the process of referencing additional external assemblies, let's update the TestApp.exe application to display a Windows Forms message box. Open your TestApp.vb file and modify it as follows:
' A simple VB 2008 application.
Module TestApp Sub Main() Console.WriteLine("Testing! 1, 2, 3")
MessageBox.Show("Hello!") End Sub End Module
Notice the reference to the System.Windows.Forms namespace via the VB 2008 Imports keyword (introduced in Chapter 1). Recall that when you explicitly list the namespaces used within a given *.vb file, you avoid the need to make use of fully qualified names (which can lead to hand cramps).
At the command line, you must inform vbc.exe which assembly contains the imported namespaces. Given that you have made use of the MessageBox class, you must specify the System.Windows.Forms.dll assembly using the /reference flag (which can be abbreviated to /r):
vbc /r:System.Windows.Forms.dll TestApp.vb
If you now rerun your application, you should see what appears in Figure 2-3 in addition to the console output.
ßjjj Administrator Visual Studio 2008 Command Prompt - TestApp.exe
C:\My Books\VB and the .NET Paltform 3rd Ed\Code\Chapter 2\ Testing! 1, 2, 3
Figure 2-3. Your first Windows Forms application
Was this article helpful?