Share via

using Visual Studio community, how do I create awindows desktop visual basic startup object main

Martin 0 Reputation points
2026-01-27T10:31:42.9833333+00:00

I have many VB applications written in Visual Basic, from 2006 to 1019, using .NET 4.8 framework. I want to upgrade to .NET 10.0 in Studio 2026.

The compiler signals differences between .Net framework and .NET core, which / can resolve. But: some applications have a Module with a Sub Main(...) which manages the Forms to use.

I open Visual Studio Community 2026, click new project, choose Windows Forms App from Visual Basic Windows Desktop. I give the project a name (TestApp). I leave Additional information as it is and click Create. In the project I add a module and insert a public sub main in the module. This sub is shown as 0 references.

I save and reopen the project, one never knows. The project contains a form Form1(.vb, .resx, .designer.vb), a module Module1.vb and a namespace My ApplicationEvents.vb with a partial class MyApplication.

In the project properties, Application part, I have Enable Windows Forms checked and in Startup object I see only TestApp.Form1. The References have System Windows Forms checked.

This does not compile. The error is BC30738: sub main is declared more than once in TestApp.My.MyApplication.Main and in TestApp.Module1.Main.

When I rename the Module1.main the project compiles and shows Form1.

When I rename Sub Main in the XML TestApp to Sub xMain, it does not compile with error BC30420 Sub Main was not found in Sub xMain

When I uncheck Enable Windows Forms (which takes some seconds to finish) it does not compile with error BC30002, because the references are completely new and don't include System.Windows.Forms anymore. After a minute or so a message appears, something like: Timeout for a named Pipe.

WHAT do I have to do here to have my Main as startup object. In .Net Framework properties showed a choice between Form1 and Main. Here it lacks.

Developer technologies | Windows Forms
0 comments No comments
{count} votes

Answer recommended by moderator
  1. Martin 0 Reputation points
    2026-01-27T11:06:13.8066667+00:00

    Messing around for another half hour I found a solution.

    1. create the project as usually: a Visual Basic Windows Forms application
    2. Add a module Module1 and insert a Public Sub Main(args as String())
    3. doubleclick the projectname in solution panel
    4. change the XML: <StartupObject>Sub Main</StartupObject> in <StartupObject>projectname.Module1</StartupObject>
    5. compile
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Martin 0 Reputation points
    2026-01-27T10:51:06.0233333+00:00

    Did it from start as described.

    in Point 3, second dot, the dropdownlist does not change, only contains TestApp.Form1

    So I save and reopen the project (one never knows....) and now I see a different drop-down list with 2 entries. first Sub Main, second TestApp.Form1. When I choose Sub Main and compile it still ends with error BC30002. Removing the startup object line in the XML gives the same result.

    0 comments No comments

  2. Q&A Assist
    2026-01-27T10:50:37.6766667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To set your Sub Main as the startup object in a Visual Basic Windows Forms application using Visual Studio Community 2026, follow these steps:

    1. Create Your Project: Start by creating a new Windows Forms App project in Visual Basic, as you have done.
    2. Add a Module: In your project, add a module (e.g., Module1.vb) and define your Sub Main as Public Sub Main(). This is where you will manage the forms.
    3. Adjust Project Properties:
      • Right-click on your project in the Solution Explorer and select Properties.
      • Navigate to the Application tab. Make sure the Enable application framework option is unchecked. This will allow you to specify your own startup object.
      • In the Startup object dropdown, you should now see your module (e.g., Module1) listed. Select it to set your Sub Main as the startup object.
    4. Resolve Conflicts: If you encounter an error stating that Sub Main is declared more than once, check for any other definitions of Sub Main in your project, such as in the MyApplication class. You may need to rename or remove any conflicting Sub Main definitions.
    5. Compile and Test: Save your changes and compile the project. Run the application to ensure it starts from your Sub Main as intended.

    If you continue to face issues, ensure that there are no other conflicting definitions and that your project references are correctly configured for .NET 10.0.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.