This documentation is archived and is not being maintained.


Specifies the class or module that contains the Sub Main procedure.



Required. A full qualification to the Sub Main procedure to be called when the program starts. This may be in the form /main:module or /main:namespace.module. location also can be a class that inherits from System.Windows.Forms.Form.


Use this option when creating an executable file or Windows executable program. If the /main option is omitted, the compiler searches for a valid shared Sub Main in all public classes and modules.

See The Visual Basic Version of Hello World! for a discussion of the various forms of the Main procedure.

When location is a class that inherits from System.Windows.Forms.Form, vbc.exe lets you compile code at the command line that was created in the development environment:

' Compile with /r:System.dll,SYSTEM.WINDOWS.FORMS.DLL /main:MyC.
Public Class MyC
   Inherits System.Windows.Forms.Form
End Class

To set /main in the Visual Studio integrated development environment

  1. Open the project's Property Pages dialog box. For details, see <Projectname> Property Pages Dialog Box.
  2. Click the Common Properties folder.
  3. Click the General property page.
  4. Modify the Startup object property.

To set /main programmatically

  • See StartupObject Property.


The following code compiles t2.vb and t3.vb, specifying that the Sub Main procedure will be found in the Test2 class:

vbc t2.vb t3.vb /main:Test2

See Also

Visual Basic Compiler Options | /target:winexe | /target:exe | Sample Compilation Command Lines