hi,
Is it possible to use a custom Sub Main on a VB2005 Windows Application project
It was possible to set the entry point to Sub Main manually in VS2003, however in 2005 I can only set it to start a form.
Thanks,
hi,
Is it possible to use a custom Sub Main on a VB2005 Windows Application project
It was possible to set the entry point to Sub Main manually in VS2003, however in 2005 I can only set it to start a form.
Thanks,
VB2005 Express - Sub Main in Windows application
Andre Guergolet
Hi Ryan,
Well, in the full version of VS2005, you can. If you go into the project properties, you can uncheck the box labeled 'Enable Application Framework'. Once that's done, the 'Startup Form:' dropdown becomes a 'Startup Object:' dropdown, and you pick your sub mains and stuff.
In VBExpress I'm not sure if it's the same deal - give it a try, and if not, then I guess you can't :)
--Geoff
GerryH
Regarding Sub Main()
1. If you implement Sub Main, it must be Public Shared, and can be in a separate Module or Class.
2. If you specify Sub Main or the class with Sub Main() defined, it will replace the built-in stub of a startup form.
3. Here is a typical Sub Main():
Public Shared Sub Main()
End Sub
It will do what you code it to do.
Regarding the Enable Application Framework:
1. No. The ApplicationContext and the main Application details are taken care of, including enabling visual styles and raising those Application Events for startup/shutdown etc.
2. This is normally the main application form, and by default, the application ends when your main form, for example the MDI Parent form for an MDI Notepad-type application, is closed.
frmMain need not be shown Modal for a Single-Instance application.
In an MDI application, you have any number of modeless forms shown (document windows, for example), and you can not show a modeless form from a Modal one.
NestorArturo
Thank you for your reply.
I don't necessarily need any great amount of control, so I'm pretty sure I'll be going with a startup form. I'll investigate how the Sub Main() helps with a splash screen later.
I do have a few more basic questions.
I have been researching this heavily since I posted, and found that if "Enable Application Framework" is selected, Sub Main() is created at compile time (where, exactly, I haven't a clue). I assume, therefore, that it is not editable in any way, nor should it be.
If I were to implement a custom Sub Main():
If I were to select "Enable Application Framework":
I've been looking at examples of login validation code, and they're all over the map.
Is it more or less typical to call frmMain as the startup form and show the frmLogin as a dialog after frmMain is shown, or to show the frmLogin first
Speaking of a "frmMain", in a single instance application - is it typical to show it as a dialog form, as well
I really wish these fundamental things were betterl covered in the books we buy.
And, speaking of books, any recommendations for a book best suited for learning VB 2005, for a person coming from a VBA background
Many thanks.
matman13
If the Application Framework is enabled, it has an internal startup that does not call your Sub Main.
It basically handles a Splash Screen (if provided), and wiring up of some events for application Startaup, Shutdown, or starting from another instance (in the event of a single-instance application).
You have less control, but the Application Framework does some of the heavy lifting for you as I described above.
By implementing a custom Sub Main, you can have far greater control, but you have to do the heavy lifting code yourself.
It is an either-or with regards to Sub Main and the Application Framework.
kobhan
Hello,
Coming from about 12 yrs of VBA coding, the jump to VB.Net is quite a task. And, I have a question further to the discussion in this thread, please.
In the article Geoff points to, I duly note the warning he refers to.
I'm posting here because I want to avoid pitfalls in an important project I've been assigned. I am making the jump directly from VBA; I haven't developed applications in any previous version of VB or Visual Studio.
The first obvious potential pitfall I've encountered is the startup option, "Enable Application Framework".
Since I don't know what "application framework" even means, exactly, the correct selection here is critically important, I assume.
Now, I have deduced from reading many posts and articles that in VB, it was typical to write a Sub Main() (in a module, I suppose) and use this module as the startup object. Something similar to an autoexec macro in VBA (Access)...again, assuming.
Further, I have deduced that the ability to do this in VB.Net is available, most likely, only for the convenience of those who are used to doing so.
Back to the MSDN article - it also states, "If Enable application framework is selected (the default), the option is Startup form, and shows only forms because the application framework only supports startup forms, not objects. In this case, your application will use the standard Sub Main."
May I infer from this statement that VB.Net still runs a "Sub Main" on startup, if you select "Enable application framework"
If so, where does "the standard Sub Main" reside Is it typical to edit it to detail what occurs when your application runs If enabling application framework only allows you to startup with a form, then what use is "Application.Run", if any For that matter, what difference is there in, for example, Form1.Show() vs. starting up with an Application.Run statement
I have Wrox's Visual Basic 2005 Programmer's Reference, and cannot find anything helpful in this area. For one thing, I think this reference is poorly indexed.
If someone can simplify this matter for me, and correct my above assumptions if they are not, I'd appreciate it.
Thank you.
Pelle Plutt
Anyone at alltravich
Fantastic. Glad to be of help.
Just remember, when you diable that option, more things happen than just being able to declare your own Sub Main().
They talk a little bit about it here: http://msdn2.microsoft.com/en-us/library/17k74w0c.aspx, but the important part is this little note:
When using a custom Sub Main procedure as the Startup object, code in the application events (Startup, Shutdown, StartupNextInstance, and UnhandledException) is not executed.
bashka66
Hi Geoff,
Thanks! the 'Enable Application Framework' option does exist in Visual Baisc 2005 Express as well!
Regards,