473,804 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB. NET Shared Sub Main()

HI,

I’m learning C# and already know VB .Net. I noticed that C# you have a
Static Void Main () (entry point of the app).

Well that got me thinking, I was told that VB.net removed “The Black Box”
of software (hidden code). Where is my Shared sub Main ()? When I create a
blank app and run it, it asked me where is Shared sub Main. So, can I assume
that it’s hidden on a win32 app? And if so, why hide it?

Thanks

Nov 21 '05 #1
15 20327
Hi Andre,

Sub Main is an standard part of dotNet.

When it is ommitted as with VBNet in the standard way than that one is taken
in the Form you choose as startup in the properties of your application. It
is not a win32 part.

It is not hidden, you just do not have to use it, however when you want,
feel free to add that class a lot of VBNet programmers are using that as I
have seen.

Cor
I'm learning C# and already know VB .Net. I noticed that C# you have a
Static Void Main () (entry point of the app).

Well that got me thinking, I was told that VB.net removed "The Black Box"
of software (hidden code). Where is my Shared sub Main ()? When I create a
blank app and run it, it asked me where is Shared sub Main. So, can I
assume
that it's hidden on a win32 app? And if so, why hide it?

Thanks

Nov 21 '05 #2
What cor states below isn't exactly correct, or at least, isn't worded
exactly correct. Every .net application requires a managed entry point. (a
"shared sub main")

However, in a windows form application the vb.net compiler will
automatically create one for you if you chose a startup form. If you choose
a form named "Form1", the code it creates is :
<STAThread> _
Public Shared Sub Main()
Application.Run (New Form1)
End Sub

Note that this code is included in your application assembly, currently
pushed into the "Form1" type. So it's as if you had typed that exact code
above into your Form1 class and set Form1.Main as your startup method.

So no, it's not really hidden, it's just conveniently created for you if you
don't write it yourself. I personally write it myself when creating VB.net
winforms apps - it removes any ambiguity when looking at the code (you don't
have to check the project properties to figure out where the app starts),
and I can easily customize the startup code.
-Philip Rieck
http://philiprieck.com/blog/
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi Andre,

Sub Main is an standard part of dotNet.

When it is ommitted as with VBNet in the standard way than that one is
taken in the Form you choose as startup in the properties of your
application. It is not a win32 part.

It is not hidden, you just do not have to use it, however when you want,
feel free to add that class a lot of VBNet programmers are using that as I
have seen.

Cor
I'm learning C# and already know VB .Net. I noticed that C# you have a
Static Void Main () (entry point of the app).

Well that got me thinking, I was told that VB.net removed "The Black Box"
of software (hidden code). Where is my Shared sub Main ()? When I create
a
blank app and run it, it asked me where is Shared sub Main. So, can I
assume
that it's hidden on a win32 app? And if so, why hide it?

Thanks


Nov 21 '05 #3
Just to add what Cor has posted, VB also has a weird quirk whereby if you
create an app, then go into the code module for the Class Form1 and change
the name to something other than Form1, you must then also go into the
project properties and tell if to use the new class name for the form as the
startup form. It assumes that it is still looking for Form1 and can no
longer find that class.

If you do not do this, you will get the error that Sub Main cannot be found.

--
Gerry O'Brien [MVP]
Visual Basic .NET(VB.NET)


"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi Andre,

Sub Main is an standard part of dotNet.

When it is ommitted as with VBNet in the standard way than that one is
taken in the Form you choose as startup in the properties of your
application. It is not a win32 part.

It is not hidden, you just do not have to use it, however when you want,
feel free to add that class a lot of VBNet programmers are using that as I
have seen.

Cor
I'm learning C# and already know VB .Net. I noticed that C# you have a
Static Void Main () (entry point of the app).

Well that got me thinking, I was told that VB.net removed "The Black Box"
of software (hidden code). Where is my Shared sub Main ()? When I create
a
blank app and run it, it asked me where is Shared sub Main. So, can I
assume
that it's hidden on a win32 app? And if so, why hide it?

Thanks


Nov 21 '05 #4
Thanks All, I wish VB.net was alittle more like C# where the code is there
for you. Maybe have a check box to show or hide the code for those that don't
want to see it.

André

"Gerry O'Brien [MVP]" wrote:
Just to add what Cor has posted, VB also has a weird quirk whereby if you
create an app, then go into the code module for the Class Form1 and change
the name to something other than Form1, you must then also go into the
project properties and tell if to use the new class name for the form as the
startup form. It assumes that it is still looking for Form1 and can no
longer find that class.

If you do not do this, you will get the error that Sub Main cannot be found.

--
Gerry O'Brien [MVP]
Visual Basic .NET(VB.NET)


"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi Andre,

Sub Main is an standard part of dotNet.

When it is ommitted as with VBNet in the standard way than that one is
taken in the Form you choose as startup in the properties of your
application. It is not a win32 part.

It is not hidden, you just do not have to use it, however when you want,
feel free to add that class a lot of VBNet programmers are using that as I
have seen.

Cor
I'm learning C# and already know VB .Net. I noticed that C# you have a
Static Void Main () (entry point of the app).

Well that got me thinking, I was told that VB.net removed "The Black Box"
of software (hidden code). Where is my Shared sub Main ()? When I create
a
blank app and run it, it asked me where is Shared sub Main. So, can I
assume
that it's hidden on a win32 app? And if so, why hide it?

Thanks



Nov 21 '05 #5
Does this show up in the code? I can't seem to find it. If I wanted to
write my own main to start the form, where would I put it? Just before the
class name?

"Philip Rieck" wrote:
What cor states below isn't exactly correct, or at least, isn't worded
exactly correct. Every .net application requires a managed entry point. (a
"shared sub main")

However, in a windows form application the vb.net compiler will
automatically create one for you if you chose a startup form. If you choose
a form named "Form1", the code it creates is :
<STAThread> _
Public Shared Sub Main()
Application.Run (New Form1)
End Sub

Note that this code is included in your application assembly, currently
pushed into the "Form1" type. So it's as if you had typed that exact code
above into your Form1 class and set Form1.Main as your startup method.

So no, it's not really hidden, it's just conveniently created for you if you
don't write it yourself. I personally write it myself when creating VB.net
winforms apps - it removes any ambiguity when looking at the code (you don't
have to check the project properties to figure out where the app starts),
and I can easily customize the startup code.
-Philip Rieck
http://philiprieck.com/blog/
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi Andre,

Sub Main is an standard part of dotNet.

When it is ommitted as with VBNet in the standard way than that one is
taken in the Form you choose as startup in the properties of your
application. It is not a win32 part.

It is not hidden, you just do not have to use it, however when you want,
feel free to add that class a lot of VBNet programmers are using that as I
have seen.

Cor
I'm learning C# and already know VB .Net. I noticed that C# you have a
Static Void Main () (entry point of the app).

Well that got me thinking, I was told that VB.net removed "The Black Box"
of software (hidden code). Where is my Shared sub Main ()? When I create
a
blank app and run it, it asked me where is Shared sub Main. So, can I
assume
that it's hidden on a win32 app? And if so, why hide it?

Thanks



Nov 21 '05 #6
It doesn't show up in the code - it is injected at compile time, so it
*does* show up in the compiled IL.

If you wanted to do it yourself, you can
1) Create a module and add a "Sub Main" to it

2) Create a class file called something like "Startup.vb " and put this in
it:
Public Class Startup
<STAThread()> _
Public Shared Sub Main()
Application.Run (new Form1)
End Sub
End Class

3) put it in your existing Form1 class (inside the class)
....
Public Class Form1
Inherits System.Windows. Forms.Form

...
<STAThread()> _
Public Shared Sub Main()
Application.Run (new Form1)
End Sub
...
End Class

It doesn't really matter what class it's in, as it's a static (Shared)
method. All you need to do is make sure that it has access to the types and
members you want (Form1 is it in this case). I prefer putting it in a
Startup.cs in c#, or a module in vb.net, but I'm sure not everyone would
agree with me.

--
-Philip Rieck
http://philiprieck.com/blog/

-
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:2C******** *************** ***********@mic rosoft.com...
Does this show up in the code? I can't seem to find it. If I wanted to
write my own main to start the form, where would I put it? Just before
the
class name?

"Philip Rieck" wrote:
What cor states below isn't exactly correct, or at least, isn't worded
exactly correct. Every .net application requires a managed entry point.
(a
"shared sub main")

However, in a windows form application the vb.net compiler will
automatically create one for you if you chose a startup form. If you
choose
a form named "Form1", the code it creates is :
<STAThread> _
Public Shared Sub Main()
Application.Run (New Form1)
End Sub

Note that this code is included in your application assembly, currently
pushed into the "Form1" type. So it's as if you had typed that exact
code
above into your Form1 class and set Form1.Main as your startup method.

So no, it's not really hidden, it's just conveniently created for you if
you
don't write it yourself. I personally write it myself when creating
VB.net
winforms apps - it removes any ambiguity when looking at the code (you
don't
have to check the project properties to figure out where the app starts),
and I can easily customize the startup code.
-Philip Rieck
http://philiprieck.com/blog/
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> Hi Andre,
>
> Sub Main is an standard part of dotNet.
>
> When it is ommitted as with VBNet in the standard way than that one is
> taken in the Form you choose as startup in the properties of your
> application. It is not a win32 part.
>
> It is not hidden, you just do not have to use it, however when you
> want,
> feel free to add that class a lot of VBNet programmers are using that
> as I
> have seen.
>
> Cor
>
>> I'm learning C# and already know VB .Net. I noticed that C# you have
>> a
>> Static Void Main () (entry point of the app).
>>
>> Well that got me thinking, I was told that VB.net removed "The Black
>> Box"
>> of software (hidden code). Where is my Shared sub Main ()? When I
>> create
>> a
>> blank app and run it, it asked me where is Shared sub Main. So, can I
>> assume
>> that it's hidden on a win32 app? And if so, why hide it?
>>
>>
>>
>> Thanks
>>
>
>


Nov 21 '05 #7
On Wed, 6 Oct 2004 10:50:11 -0500, Philip Rieck wrote:
So no, it's not really hidden, it's just conveniently created for you if you
don't write it yourself. I personally write it myself when creating VB.net


Since you cannot see it, then by definition, it is hidden. The OP was just
making the observation that VB.Net was supposed to have eliminated that
type of "Black Box" functionality. Yet it still exists.

--
Chris

dunawayc[AT]sbcglobal_lunch meat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #8
Andre
Thanks All, I wish VB.net was alittle more like C# where the code is
there
for you. Maybe have a check box to show or hide the code for those that
don't
want to see it.


In VBNet is as well all the code for you, the only thing is that there is in
this case used a feature of the .Net framework what is not done in C#.

In C# you cannot use it, in VBNet you are free to use it.

Cor

Nov 21 '05 #9
"Gerry O'Brien [MVP]" <gerry dot obrien at gmail dot com> schrieb:
Just to add what Cor has posted, VB also has a weird quirk whereby if you
create an app, then go into the code module for the Class Form1 and change
the name to something other than Form1, you must then also go into the
project properties and tell if to use the new class name for the form as
the startup form. It assumes that it is still looking for Form1 and can
no longer find that class.

If you do not do this, you will get the error that Sub Main cannot be
found.


ACK, but VS.NET will kindly show a dialog that allows picking the new
startup object :-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4412
by: Srijit Kumar Bhadra | last post by:
Hello, Here is some sample code with pywin32 build 203 and ctypes 0.9.6. Best regards, /Srijit File: SharedMemCreate_Mutex_win32all.py # This application should be used with SharedMemAccess_Mutex_ctypes.py or SharedMemAccess_Mutex_win32all.py
20
3349
by: andre | last post by:
HI, I’m learning C# and already know VB .Net. I noticed that C# you have a Static Void Main () (entry point of the app). Well that got me thinking, I was told that VB.net removed “The Black Box” of software (hidden code). Where is my Shared sub Main ()? When I create a blank app and run it, it asked me where is Shared sub Main. So, can I assume that it’s hidden on a win32 app? And if so, why hide it?
4
1552
by: jon.apostoles | last post by:
I have a program that is going to have plugins used for various capabilities. The main program creates a class (AppCore) which handles everything. This class contains another class (PluginController) that handles loading the shared objects via the dl* functions. When I create the plugins, I link them using -shared. The plugins themselves are derived from a class (Plugin)... inside of the Plugin class there is a variable to hold a...
10
3576
by: John Brock | last post by:
I have a base class with several derived classes (I'm writing in VB.NET). I want each derived class to have a unique class ID (a String), and I want the derived classes to inherit from the base class *Shared* methods which make use of the class ID. So I gave the base class a classID field, and then I gave the derived classes Shared constructors, which I used to set the classID field to the appropriate values for each derived class. But...
7
5216
by: Steve | last post by:
Hi, We have an application framework library that gets statically linked to any applications we produce. (Windows apps, but I don't think that matters here). The framework is based heavily on the STL and the API uses many STL constructs. Because of the static linking, and the fact that both app and framework are built by the same compiler, we don't have any problems.
1
1869
by: izhar.wallach | last post by:
Hi, I'm trying to write an application which have a component that I like to modify without restarting it. Thus, I was thinking of using a shared object for that component. However, in the example below, I haven't figured out a way to modify commonClass.cpp (for example, the print() method) and be able to see the changes without rerunning the application. I can see changes made directly in sharedClass.cpp, though. Is there a way to see...
3
2252
by: tropos | last post by:
(Platform: Solaris with gmake and native Sun C++ compiler) Problem: If I create a shared object (.so file) and load it into a executable, the loader correctly runs constructors of static objects in the .so file. But if I link the same code statically, with no shared object, then the constructors don't run at all! Why?? Here's an example: <file AnnounceConstruction.cpp>
2
3093
by: shahehe | last post by:
Hi I have overloaded new in a shared library (s1.so) sucessfully. but I do not what main program and any other shared library to be able to use this new operator. In other words, I do not operator new to be globally used. I tried some ld options -Bsymbolic as follows g++ -shared -Wl,-Bysmbolic f1.o -o s1.so
7
3396
by: akennis | last post by:
First of all, sorry for duplicating this post. I put it up in the alt.comp.lang.learn.c-c++ mistakenly. I'm investigating a problem whereby exceptions thrown from functions in a Shared Library which was dynamically loaded (dlopen) are not properly caught by the caller. Specifically, when compiling with G++ version 4.0, the RTTI data associated with the exception types is not being properly aligned between the Shared Library and its...
1
2671
by: athresh | last post by:
I have created a shared library with main() .Still it is compiled and loaded during invocation. Below is the code and build file. sample_test.cpp int test_method(CfgChkSession &s) { cout<<"working"<<endl; return 1; }
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10351
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9174
agi2029
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6866
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.