|
|
Title | Start a program from Sub Main in Visual Basic 2005 and later |
Description | This example shows how to start a program from Sub Main in Visual Basic 2005 and later. |
Keywords | Sub Main, start, start application, start proigram, Visual Basic, Visual Basic 2005 |
Categories | Software 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:
- Create a new Windows Forms project.
- In the Project Explorer, double-click the "My Project" entry to open the project's property pages.
- Uncheck the "Enable application framework" check box (circled in the figure).
- 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
|
|
|
|
|
|