[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1237
  • Last Modified:

Getting VB.NET 2008 to go to Sub Main() on startup

Hello Experts -

I'm trying to get VB.NET 2008 to goto Sub Main() instead of the startup form. The reason why is that the logic in Sub Main() will determinde which form is shown.

When I put Sub Main() in a Module, VB ignores it and goes to the default startup form.

Any thoughts?
0
gbmcneil
Asked:
gbmcneil
  • 4
  • 4
  • 3
  • +1
1 Solution
 
ToxaconCommented:
Use the form selection logic in the startup form. Hide the startup form before it's shown during form_load. You can also make a stylish start with a splash screen which has the main form selection logic in it.
0
 
gbmcneilAuthor Commented:
You are saying that I can't get VB.NET to go to my Sub Main() in a module?
0
 
nepaluzCommented:
You can do it IF you do not select to create a Windows Forms application.
Choose to create a class (and remember to include the system.windows.forms) when creating your forms.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ToxaconCommented:
You can call the Main() as any other procedure but after finishing it will go to the startup form.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can...just go to Project --> Properties and UNCHECK the "Enable Application Framework" box.  Then you can change the "Startup Object" to "Sub Main"
0
 
ToxaconCommented:
If you disable the Application Framework, you have to programmatically take care of visual styles, proper shutdown/form handling etc...
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Re-reading the question, he has:

    "The reason why is that the logic in Sub Main() will determinde which form is shown."

To change the startup form, use the Application.Startup() event (Project --> Properties --> "View Application Events" button in the bottom right.)

From the Startup() event, you can put your logic in and change the Application.MainForm property to an instance of your choosing:
Namespace My

    ' The following events are available for MyApplication:
    ' 
    ' Startup: Raised when the application starts, before the startup form is created.
    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    ' UnhandledException: Raised if the application encounters an unhandled exception.
    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    Partial Friend Class MyApplication

        Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
            If Date.Today.DayOfWeek = DayOfWeek.Tuesday Then
                Application.MainForm = New Form1
            Else
                Application.MainForm = New Form2
            End If
        End Sub

    End Class


End Namespace

Open in new window

0
 
gbmcneilAuthor Commented:
That mind of yours is not very idle, Idle Mind. You've hit the nail on the head.

Your solution is exactly what I needed.

Thanks very much.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Glad that was helpful.

Just FYI, you can also CANCEL the app from the Startup() Event by setting "e.Cancel = True",  giving you the ability to shutdown the app WITHOUT showing any forms at all.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
See "Overview of the Visual Basic Application Model":
http://msdn.microsoft.com/en-us/library/w3xx6ewx(VS.80).aspx
0
 
gbmcneilAuthor Commented:
Thanks again. Good info to know.
0
 
gbmcneilAuthor Commented:
Thanks fot your help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now