/mainĀ 

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

/main:location

Arguments

  • location
    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 can also be a class that inherits from Form.

Remarks

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 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 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. Have a project selected in Solution Explorer. On the Project menu, click Properties.

    For more information, see Introduction to the Project Designer.

  2. Click the Application tab.

  3. Make sure the Enable application framework checkbox is not checked.

  4. Modify the value in the Startup object box.

Example

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

Reference

/target (Visual Basic)
Sample Compilation Command Lines

Concepts

Main Procedure in Visual Basic

Other Resources

Visual Basic Compiler