Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleStart a program from Sub Main in Visual Basic 2005 and later
DescriptionThis example shows how to start a program from Sub Main in Visual Basic 2005 and later.
KeywordsSub Main, start, start application, start proigram, Visual Basic, Visual Basic 2005
CategoriesSoftware Engineering
 
When you create a new Windows Forms application, Visual Basic assumes that it will start from a form and run until that form is closed. To make the program start by running Sub Main, follow these steps:

  1. Create a new Windows Forms project.
  2. In the Project Explorer, double-click the "My Project" entry to open the project's property pages.
  3. Uncheck the "Enable application framework" check box (circled in the figure).
  4. In the "Startup object" dropdown, select "Sub Main."

The following code shows the example program's Sub Main routine in the module MainModule.vb. It displays a message box, displays a new form modally, and then displays another message before ending. (Try using Show instead of ShowDialog to display the form and see what happens.)

 
Module MainModule
    Public Sub Main()
        MessageBox.Show("In Sub Main", "Sub Main", _
            MessageBoxButtons.OK, _
            MessageBoxIcon.Information)

        Dim frm As New Form1
        frm.ShowDialog()

        MessageBox.Show("Done", "Done", _
            MessageBoxButtons.OK, _
            MessageBoxIcon.Information)
    End Sub
End Module
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated