The current incarnation of the TestApp.exe application was created using a single *.vb source code file. While it is perfectly permissible to have all of your .NET types defined in a single *.vb file, most projects are composed of multiple *.vb files to keep your code base a bit more flexible. Assume you have authored an additional class (again, using Notepad) contained in a new file named HelloMsg.vb:
' The HelloMessage class
Class HelloMessage Sub Speak()
MessageBox.Show("Hello Again") End Sub End Class
Assuming you have saved this new file in the same location as your first file (e.g., C:\VbcExample), update your TestApp class to make use of this new type, and comment out the previous Windows Forms logic. Here is the complete update:
' A simple VB 2008 application.
' Don't need this anymore. ' Imports System.Windows.Forms
Module TestApp Sub Main() Console.WriteLine("Testing! 1, 2, 3")
' Don't need this anymore either. ' MessageBox.Show("Hello!")
' Exercise the HelloMessage class!
Dim hello As New HelloMessage() hello.Speak() End Sub End Module
You can compile your VB 2008 files by listing each input file explicitly:
vbc /r:System.Windows.Forms.dll TestApp.vb HelloMsg.vb
As an alternative, the VB 2008 compiler allows you to make use of the wildcard character (*) to inform vbc.exe to include all *.vb files contained in the project directory as part of the current build:
vbc /r:System.Windows.Forms.dll *.vb
When you run the program again, the output is identical. The only difference between the two applications is the fact that the current logic has been split among multiple files.
Was this article helpful?