Hi
What is the closest equivalent to Main in a VB.Net form?
Geoff 16 2093
"Geoff Jones" <no********@email.com> schrieb: What is the closest equivalent to Main in a VB.Net form?
Inside your form class' code:
\\\
Public Shared Sub Main()
...
End Sub
///
In the project properties, select 'Sub Main' as the startup object.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Herfried, In the project properties, select 'Sub Main' as the startup object.
Or simply select the Form's class as the startup object. VB.NET will see the
Form class has a Shared Sub Main & use it, rather then implicitly adding
one.
Form example I normally have a MainForm class.
Public Class MainForm
Inherits System.Windows.Forms.Form
... designer generated code & other code
Public Shared Sub Main()
...
End Sub
End Class
Then in my Project Properties I have MainForm selected as the startup
object.
I'm not sure when I would ever actually select "Sub Main" as the startup
object...
Hope this helps
Jay
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eU**************@TK2MSFTNGP12.phx.gbl... "Geoff Jones" <no********@email.com> schrieb: What is the closest equivalent to Main in a VB.Net form?
Inside your form class' code:
\\\ Public Shared Sub Main() ... End Sub ///
In the project properties, select 'Sub Main' as the startup object.
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Jay,
I see no real advantage in this VB.NET will see the Form class has a Shared Sub Main & use it, rather then implicitly adding one.
I am glad that at least is again leaved that way that the start point in a
program should be called "main".
So I am glad that it is implicitly added.
Not that important just to tell my thoughts about that.
Cor
Cor,
You see no real advantage in what?
Select one of:
A. Explicitly defining a Shared Sub Main
B. VB.NET implicitly creating a Main if you don't supply one
C. VB.NET using a Sub Main
D. Selecting the Form with a Sub Main as the startup object
E. Selecting Sub Main as the startup object
F. Defining Sub Main in a Form
G. Defining Sub Main in another Class
H. Defining Sub Main in a Module
I. Using "Main" as the name of the Startup routine
J. Some other obscure factoid
I really cannot make out what you don't see a real advantage to...
Thanks for any potential clarification you can make.
Jay
"Cor Ligthert" <no************@planet.nl> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl... Jay,
I see no real advantage in this
VB.NET will see the Form class has a Shared Sub Main & use it, rather then implicitly adding one.
I am glad that at least is again leaved that way that the start point in a program should be called "main".
So I am glad that it is implicitly added.
Not that important just to tell my thoughts about that.
Cor
Jay,
Nice multiple choise thanks and nice showing of all the possibilities as
well.
This answer from me only for a webform or windowform project, than I find B
the nicest and can not see a reason for all those others than that it is old
fashion use.(By a lot of people used as good practise).
And when that is the reason than that is no reason for me.
Cor Cor, You see no real advantage in what?
Select one of: A. Explicitly defining a Shared Sub Main B. VB.NET implicitly creating a Main if you don't supply one C. VB.NET using a Sub Main D. Selecting the Form with a Sub Main as the startup object E. Selecting Sub Main as the startup object F. Defining Sub Main in a Form G. Defining Sub Main in another Class H. Defining Sub Main in a Module I. Using "Main" as the name of the Startup routine J. Some other obscure factoid
Jay,
When there was not an implcitly sub main I would choise your solution by the
way.
That is A as I see it well.
Cor Select one of: A. Explicitly defining a Shared Sub Main B. VB.NET implicitly creating a Main if you don't supply one C. VB.NET using a Sub Main D. Selecting the Form with a Sub Main as the startup object E. Selecting Sub Main as the startup object F. Defining Sub Main in a Form G. Defining Sub Main in another Class H. Defining Sub Main in a Module I. Using "Main" as the name of the Startup routine J. Some other obscure factoid
"Cor Ligthert" <no************@planet.nl> schrieb: Nice multiple choise thanks and nice showing of all the possibilities as well.
This answer from me only for a webform or windowform project, than I find B the nicest and can not see a reason for all those others than that it is old fashion use.(By a lot of people used as good practise).
I don't see why using 'Sub Main' should be old-fashion. Every application
has a starting point, and if the developer wants/needs to influence the
startup of the application, defining a 'Sub Main' is the way to go.
What I (personally) don't like is a 'Sub Main' defined inside a form.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Herfried, What I (personally) don't like is a 'Sub Main' defined inside a form.
Does that go for other classes as well? For example Windows Services, puts
the Sub Main in the class derived from ServiceBase. When I define a system
tray application I normally put my Sub Main in the Main Component (the
object that manages the context menu & notify icon objects).
Do you normally define it in a Module? What do you normally call the module.
When I define my Sub Main in a module I normally call that module
MainModule. This is one of the few times I actually use a Module.
As I stated, I normally define my Sub Main in the MainForm, especially when
there is a "well-defined" MainForm...
Just wondering
Jay
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ey**************@TK2MSFTNGP11.phx.gbl... "Cor Ligthert" <no************@planet.nl> schrieb: Nice multiple choise thanks and nice showing of all the possibilities as well.
This answer from me only for a webform or windowform project, than I find B the nicest and can not see a reason for all those others than that it is old fashion use.(By a lot of people used as good practise).
I don't see why using 'Sub Main' should be old-fashion. Every application has a starting point, and if the developer wants/needs to influence the startup of the application, defining a 'Sub Main' is the way to go.
What I (personally) don't like is a 'Sub Main' defined inside a form.
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Jay,
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
That's a discussion about personal preference... What I (personally) don't like is a 'Sub Main' defined inside a form. Does that go for other classes as well? For example Windows Services, puts the Sub Main in the class derived from ServiceBase. When I define a system tray application I normally put my Sub Main in the Main Component (the object that manages the context menu & notify icon objects).
Do you normally define it in a Module? What do you normally call the module.
I prefer a module if I want to explicitly control the entry point:
\\\
Public Module Program
Public Sub Main()
...
End Sub
End Module
///
When I define my Sub Main in a module I normally call that module MainModule. This is one of the few times I actually use a Module.
It's similar for me. I try to use modules for my 'Sub Main' too (as always
with some exceptions).
As I stated, I normally define my Sub Main in the MainForm, especially when there is a "well-defined" MainForm...
When there is a "well-defined" main form, it's ok to add the 'Sub Main'
directly to the form class. Nevertheless, when taking a look at the
projects which can be found on the web, it's often hard to locate the 'Sub
Main'/'void Main' there because people use unmeaningful names for their
classes/forms.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Herfried, I don't see why using 'Sub Main' should be old-fashion. Every application has a starting point, and if the developer wants/needs to influence the startup of the application, defining a 'Sub Main' is the way to go.
What I (personally) don't like is a 'Sub Main' defined inside a form.
True, every application has a starting point however with the introduction
of the thirth generation programlanguages, that became more and more that
that should be named a kind of "Main".
That was in my opinion an easy way for the compiler builders to find that. A
little descripting way where you could say that a program was starting in a
certain method was leaved then. That is now reintroduced in VBNet, I find
that an improvement again.
A nice descripting way (as Jay as well suggest in this thread), is in my
opinion much nicer.
When that is in English it can be MainForm, however for me as well
StartForm, or whatever and when it is not in the English language by
instance PrimoPagina (to use a fictive language).
Just my thought of course.
Cor
Cor, certain method was leaved then. That is now reintroduced in VBNet, I find that an improvement again.
"reintroduced"?
VB1 thru VB6 had the ability to define a "Sub Main" in a module to be used
as the entry point instead of an actual form. (Yes I just checked the VB1
manual :-))
VB.NET allows the Sub Main to be in a class or module as VB.NET allows
Shared Subs in classes.
Hope this helps
Jay
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eq*************@TK2MSFTNGP09.phx.gbl... Herfried,
I don't see why using 'Sub Main' should be old-fashion. Every application has a starting point, and if the developer wants/needs to influence the startup of the application, defining a 'Sub Main' is the way to go.
What I (personally) don't like is a 'Sub Main' defined inside a form.
True, every application has a starting point however with the introduction of the thirth generation programlanguages, that became more and more that that should be named a kind of "Main".
That was in my opinion an easy way for the compiler builders to find that. A little descripting way where you could say that a program was starting in a certain method was leaved then. That is now reintroduced in VBNet, I find that an improvement again.
A nice descripting way (as Jay as well suggest in this thread), is in my opinion much nicer. When that is in English it can be MainForm, however for me as well StartForm, or whatever and when it is not in the English language by instance PrimoPagina (to use a fictive language).
Just my thought of course.
Cor
Herfried, That's a discussion about personal preference...
Yes this is largely a discussion of personal preference.
Nevertheless, when taking a look at the projects which can be found on the web, it's often hard to locate the 'Sub Main'/'void Main' there because people use unmeaningful names for their classes/forms.
Agree.
Which is largely why I call the "main" form MainForm (with or without a Sub
Main) or put Sub Main in the MainModule.
In my Windows Service projects so far I have left in the Service's class
that is derived from ServiceBase... I really should move it to a
MainModule...
Hope this helps
Jay
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... Jay,
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
That's a discussion about personal preference...
What I (personally) don't like is a 'Sub Main' defined inside a form. Does that go for other classes as well? For example Windows Services, puts the Sub Main in the class derived from ServiceBase. When I define a system tray application I normally put my Sub Main in the Main Component (the object that manages the context menu & notify icon objects).
Do you normally define it in a Module? What do you normally call the module.
I prefer a module if I want to explicitly control the entry point:
\\\ Public Module Program Public Sub Main() ... End Sub End Module ///
When I define my Sub Main in a module I normally call that module MainModule. This is one of the few times I actually use a Module.
It's similar for me. I try to use modules for my 'Sub Main' too (as always with some exceptions).
As I stated, I normally define my Sub Main in the MainForm, especially when there is a "well-defined" MainForm...
When there is a "well-defined" main form, it's ok to add the 'Sub Main' directly to the form class. Nevertheless, when taking a look at the projects which can be found on the web, it's often hard to locate the 'Sub Main'/'void Main' there because people use unmeaningful names for their classes/forms.
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Jay, VB1 thru VB6 had the ability to define a "Sub Main" in a module to be used as the entry point instead of an actual form. (Yes I just checked the VB1 manual :-))
Ahh that it is why Herfried wants to do it in his eyes maybe more grown up
language way, thinking it was an advantage of those languages.
For me is VBNet enough grown up to do it in that in my opinion more
descriptive way (when you do it right of course as we both write).
:-))
Thanks for waking me up (I knew it, just a stupidity writing it that way,
however the contexts stays for me).
Cor
Hello...
I also prefer startup in a module.
I normally have mine named modStartup.
I found it was easier and quicker when testing multiple forms to just
change the form that gets called then to constantly change it using the
project properties dialog.
Also makes it easy to add/modify application level attributes/variables
such as Application.EnableVisualStyles()etc...
I usually have mine auto generated for each new project (I modified the
project template VS uses)...
Just my thoughts on the matter.
Marc Cramer
Herfried K. Wagner [MVP] wrote: Jay,
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
That's a discussion about personal preference...
What I (personally) don't like is a 'Sub Main' defined inside a form.
Does that go for other classes as well? For example Windows Services, puts the Sub Main in the class derived from ServiceBase. When I define a system tray application I normally put my Sub Main in the Main Component (the object that manages the context menu & notify icon objects).
Do you normally define it in a Module? What do you normally call the module.
I prefer a module if I want to explicitly control the entry point:
\\\ Public Module Program Public Sub Main() ... End Sub End Module ///
When I define my Sub Main in a module I normally call that module MainModule. This is one of the few times I actually use a Module.
It's similar for me. I try to use modules for my 'Sub Main' too (as always with some exceptions).
As I stated, I normally define my Sub Main in the MainForm, especially when there is a "well-defined" MainForm...
When there is a "well-defined" main form, it's ok to add the 'Sub Main' directly to the form class. Nevertheless, when taking a look at the projects which can be found on the web, it's often hard to locate the 'Sub Main'/'void Main' there because people use unmeaningful names for their classes/forms. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kwan Ting |
last post by:
The_Sage, I see you've gotten yourself a twin asking for program in
comp.lang.c++ .
http://groups.google.co.uk/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=45cd1b289c71c33c&rnum=1
If you the oh so mighty...
|
by: Steven T. Hatton |
last post by:
This is a purely *hypothetical* question. That means, it's /pretend/,
CP. ;-)
If you were forced at gunpoint to put all your code in classes, rather than
in namespace scope (obviously classes...
|
by: Fred Zwarts |
last post by:
In C++ execution of a program starts already before execution of main().
The initialization of static variables defined outside the scope of main
is performed first. I could imagine a program where...
|
by: Beni |
last post by:
I have been programming in C for about a year now. It sounds silly,
but I never took the time to question why a C(or C++ or Java) program
execution begins only at the main(). Is it a convention or...
|
by: Seong-Kook Shin |
last post by:
Hi, I'm reading Steve's "C Programming FAQs" in book version,
and have two question regarding to Q11.16
... Also, a `return' from `main' cannot be expected to work if
data local to main might be...
|
by: Sokar |
last post by:
I have my main function set up as
int main(int argv, char *argv)
so taht i can read in a variable which is passed to the program on the
command line. The problem is that main calls other...
|
by: psuaudi |
last post by:
I have a main query that I would like to call two different subqueries.
In MS Access, I usually just save the two subqueries as separate queries which are then called by a third separate and main...
|
by: ravi |
last post by:
Hello everybody,
I am writing a small application which does some work before the user
main function starts execution.
I am trying to #define the main function.
But the problem is that,
|
by: aarklon |
last post by:
Hi all,
I have heard many discussions among my colleagues that main is a user
defined function or not.
arguments in favour:-
1) if it is built in function it must be defined in some header...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |