From 4010b3b9c53763266a64d1e242fa7c97b773f217 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Sep 2025 20:44:01 +0000 Subject: [PATCH 1/5] Initial plan From 09285fcfe01e6824da9c4ee28cebd5d3f77d4a5b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Sep 2025 20:48:26 +0000 Subject: [PATCH 2/5] Enhance BC30738 error documentation with Windows Forms and My.MyApplication guidance Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- docs/visual-basic/misc/bc30738.md | 46 +++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/docs/visual-basic/misc/bc30738.md b/docs/visual-basic/misc/bc30738.md index 5890c982577d3..743986dfe7951 100644 --- a/docs/visual-basic/misc/bc30738.md +++ b/docs/visual-basic/misc/bc30738.md @@ -11,14 +11,44 @@ ms.assetid: c3212d87-6af3-4120-9e06-4d85fa910de2 --- # 'Sub Main' is declared more than once in '\': \ -`Sub Main` can only be declared once inside a namespace. - - **Error ID:** BC30738 - -## To correct this error - -- Make sure there is only a single `Sub Main` procedure in your project. - +`Sub Main` can only be declared once inside a namespace. + +**Error ID:** BC30738 + +## Cause + +This error commonly occurs in Windows Forms applications when you attempt to define your own `Sub Main` procedure while the Visual Basic Application Framework is enabled. The application framework automatically generates a `Main` procedure, creating a conflict when you add another one. + +## To correct this error + +Choose one of the following approaches: + +### Option 1: Use the Application Framework (Recommended for most Windows Forms apps) + +1. Remove your custom `Sub Main` procedure. +1. Configure your startup form and initialization code using the application framework: + - Set the **Startup form** in **Project Properties** > **Application** tab. + - Use the `My.MyApplication` events for custom startup logic. + +### Option 2: Disable the Application Framework + +If you need programmatic control over application startup (for example, to select which form to display based on command-line arguments): + +1. In **Project Properties** > **Application** tab, uncheck **Enable application framework**. +1. Set **Startup object** to your module or class containing `Sub Main`. +1. Implement your own `Sub Main` procedure to control application startup. + +### Option 3: Remove duplicate Main procedures + +- Ensure there is only a single `Sub Main` procedure in your entire project. + +## Accessing My.MyApplication.Main + +If you need to access the automatically generated startup code, you can work with the `My.MyApplication` object and its events such as `Startup`, `StartupNextInstance`, and `Shutdown`. The application framework provides these events specifically for customizing application behavior without defining your own `Main` procedure. + ## See also +- [Main Procedure in Visual Basic](../programming-guide/program-structure/main-procedure.md) +- [Overview of the Visual Basic Application Model](../developing-apps/development-with-my/overview-of-the-visual-basic-application-model.md) +- [-main (Visual Basic)](../reference/command-line-compiler/main.md) - [Procedures](../programming-guide/language-features/procedures/index.md) From d60f684dd62b69adaa52089e1f0b7398e2f61813 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Tue, 16 Sep 2025 10:02:44 -0400 Subject: [PATCH 3/5] Apply suggestions from code review --- docs/visual-basic/misc/bc30738.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/visual-basic/misc/bc30738.md b/docs/visual-basic/misc/bc30738.md index 743986dfe7951..61ea5feee1aa8 100644 --- a/docs/visual-basic/misc/bc30738.md +++ b/docs/visual-basic/misc/bc30738.md @@ -17,7 +17,7 @@ ms.assetid: c3212d87-6af3-4120-9e06-4d85fa910de2 ## Cause -This error commonly occurs in Windows Forms applications when you attempt to define your own `Sub Main` procedure while the Visual Basic Application Framework is enabled. The application framework automatically generates a `Main` procedure, creating a conflict when you add another one. +This error often occurs in Windows Forms applications when you define your own `Sub Main` procedure while the Visual Basic Application Framework is enabled. The application framework automatically generates a `Main` procedure, creating a conflict when you add another one. ## To correct this error @@ -25,18 +25,18 @@ Choose one of the following approaches: ### Option 1: Use the Application Framework (Recommended for most Windows Forms apps) -1. Remove your custom `Sub Main` procedure. -1. Configure your startup form and initialization code using the application framework: - - Set the **Startup form** in **Project Properties** > **Application** tab. - - Use the `My.MyApplication` events for custom startup logic. +- Remove your custom `Sub Main` procedure. +- Configure your startup form and initialization code using the application framework: + - Set the **Startup form** in **Project Properties** > **Application** tab. + - Use the `My.MyApplication` events for custom startup logic. ### Option 2: Disable the Application Framework If you need programmatic control over application startup (for example, to select which form to display based on command-line arguments): -1. In **Project Properties** > **Application** tab, uncheck **Enable application framework**. -1. Set **Startup object** to your module or class containing `Sub Main`. -1. Implement your own `Sub Main` procedure to control application startup. +- In **Project Properties** > **Application** tab, uncheck **Enable application framework**. +- Set **Startup object** to your module or class containing `Sub Main`. +- Implement your own `Sub Main` procedure to control application startup. ### Option 3: Remove duplicate Main procedures From d329f39aa9fc1e7fc1baf9b930625db7e18f91dd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 16 Sep 2025 14:07:10 +0000 Subject: [PATCH 4/5] Use xref syntax for My.MyApplication and events Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- docs/visual-basic/misc/bc30738.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/visual-basic/misc/bc30738.md b/docs/visual-basic/misc/bc30738.md index 61ea5feee1aa8..92bae73538173 100644 --- a/docs/visual-basic/misc/bc30738.md +++ b/docs/visual-basic/misc/bc30738.md @@ -44,7 +44,7 @@ If you need programmatic control over application startup (for example, to selec ## Accessing My.MyApplication.Main -If you need to access the automatically generated startup code, you can work with the `My.MyApplication` object and its events such as `Startup`, `StartupNextInstance`, and `Shutdown`. The application framework provides these events specifically for customizing application behavior without defining your own `Main` procedure. +If you need to access the automatically generated startup code, you can work with the object and its events such as , , and . The application framework provides these events specifically for customizing application behavior without defining your own `Main` procedure. ## See also From 6b768e4e3652262bab75c528379bab419da696a1 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Wed, 17 Sep 2025 11:29:05 -0400 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- docs/visual-basic/misc/bc30738.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/visual-basic/misc/bc30738.md b/docs/visual-basic/misc/bc30738.md index 92bae73538173..4a41409358907 100644 --- a/docs/visual-basic/misc/bc30738.md +++ b/docs/visual-basic/misc/bc30738.md @@ -23,14 +23,14 @@ This error often occurs in Windows Forms applications when you define your own ` Choose one of the following approaches: -### Option 1: Use the Application Framework (Recommended for most Windows Forms apps) +### Option 1: Use the application framework (recommended for most Windows Forms apps) - Remove your custom `Sub Main` procedure. - Configure your startup form and initialization code using the application framework: - Set the **Startup form** in **Project Properties** > **Application** tab. - Use the `My.MyApplication` events for custom startup logic. -### Option 2: Disable the Application Framework +### Option 2: Disable the application framework If you need programmatic control over application startup (for example, to select which form to display based on command-line arguments): @@ -42,7 +42,7 @@ If you need programmatic control over application startup (for example, to selec - Ensure there is only a single `Sub Main` procedure in your entire project. -## Accessing My.MyApplication.Main +## Access `My.MyApplication.Main` If you need to access the automatically generated startup code, you can work with the object and its events such as , , and . The application framework provides these events specifically for customizing application behavior without defining your own `Main` procedure.