JumpyNET Posted June 4, 2005 Posted June 4, 2005 How can I change my program to start from "Sub Main"? I have only found a selection for "Startup Form". I do not always need to show the main form before exit. Quote
Leaders snarfblam Posted June 4, 2005 Leaders Posted June 4, 2005 have you tried putting a Public Shared Sub Main in the form's code? Quote [sIGPIC]e[/sIGPIC]
JumpyNET Posted June 4, 2005 Author Posted June 4, 2005 (edited) have you tried putting a Public Shared Sub Main in the form's code? Doesn't it then load all the objects I have used in my main form? I want to be sure nothing unnecessary is loaded. Especially I don't want to load the MediaPlayer dll if it is not needed. Sometimes it is needed and sometimes not. Besides it didn't work. I tried to put this in my main form's class, but the form opens up normally: Public Shared Sub Main(ByVal CmdArgs() As String) End End Sub Edited June 4, 2005 by JumpyNET Quote
Leaders snarfblam Posted June 4, 2005 Leaders Posted June 4, 2005 Google comes to the rescue! A Google search for vb.net 2005 "sub main" yields this. Microsoft has introduced the Application Framework which encapsulates many tasks associated with creating an application. One of the function provided by the Application Framework is to start your application up for you on its own terms, which does not include a Sub Main. Visit the link to learn how to work around this issue. Quote [sIGPIC]e[/sIGPIC]
JumpyNET Posted June 6, 2005 Author Posted June 6, 2005 I think I will switch to C# because in C# instead of "Start up form" there is a "Startup object" which allows the use of Main. Quote
Leaders snarfblam Posted June 6, 2005 Leaders Posted June 6, 2005 Did you read what I linked to? Quote [sIGPIC]e[/sIGPIC]
mskeel Posted June 6, 2005 Posted June 6, 2005 The easiest way to get to the startup object in VB.net is to create a .Net Console App and then just call the form if you need to in the sub main there. This thread might be helpful... But, alas, I am talking about VS 2003...this may still be applicable for you. Quote
JumpyNET Posted June 7, 2005 Author Posted June 7, 2005 (edited) Problem solved!! I found this in AplicationEvents.vb. The Startup seems just what I'm looking for. :D Thanks for your help marble_eater and mskeel!! 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 is terminating 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. Class MyApplication Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup MsgBox("Bye bye!") End End Sub End Class End Namespace Edited June 7, 2005 by JumpyNET Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.