VB. NET Shared Sub Main()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • andre@online.nospam

    #1

    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

  • Philip Rieck

    #2
    Re: VB. NET Shared Sub Main()

    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



    "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
    news:%2344dWo7q EHA.2604@TK2MSF TNGP10.phx.gbl. ..[color=blue]
    > 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
    >[color=green]
    >> 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
    >>[/color]
    >
    >[/color]


    Comment

    • Cor Ligthert

      #3
      Re: VB. NET Shared Sub Main()

      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
      [color=blue]
      > 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
      >[/color]


      Comment

      • Gerry O'Brien [MVP]

        #4
        Re: VB. NET Shared Sub Main()

        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" <notmyfirstname @planet.nl> wrote in message
        news:%2344dWo7q EHA.2604@TK2MSF TNGP10.phx.gbl. ..[color=blue]
        > 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
        >[color=green]
        >> 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
        >>[/color]
        >
        >[/color]


        Comment

        • Philip Rieck

          #5
          Re: VB. NET Shared Sub Main()

          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



          "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
          news:%2344dWo7q EHA.2604@TK2MSF TNGP10.phx.gbl. ..[color=blue]
          > 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
          >[color=green]
          >> 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
          >>[/color]
          >
          >[/color]


          Comment

          • Gerry O'Brien [MVP]

            #6
            Re: VB. NET Shared Sub Main()

            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" <notmyfirstname @planet.nl> wrote in message
            news:%2344dWo7q EHA.2604@TK2MSF TNGP10.phx.gbl. ..[color=blue]
            > 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
            >[color=green]
            >> 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
            >>[/color]
            >
            >[/color]


            Comment

            • andre@online.nospam

              #7
              Re: VB. NET Shared Sub Main()

              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:
              [color=blue]
              > 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" <notmyfirstname @planet.nl> wrote in message
              > news:%2344dWo7q EHA.2604@TK2MSF TNGP10.phx.gbl. ..[color=green]
              > > 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
              > >[color=darkred]
              > >> 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
              > >>[/color]
              > >
              > >[/color]
              >
              >
              >[/color]

              Comment

              • andre@online.nospam

                #8
                Re: VB. NET Shared Sub Main()

                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:
                [color=blue]
                > 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" <notmyfirstname @planet.nl> wrote in message
                > news:%2344dWo7q EHA.2604@TK2MSF TNGP10.phx.gbl. ..[color=green]
                > > 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
                > >[color=darkred]
                > >> 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
                > >>[/color]
                > >
                > >[/color]
                >
                >
                >[/color]

                Comment

                • Dennis

                  #9
                  Re: VB. NET Shared Sub Main()

                  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:
                  [color=blue]
                  > 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" <notmyfirstname @planet.nl> wrote in message
                  > news:%2344dWo7q EHA.2604@TK2MSF TNGP10.phx.gbl. ..[color=green]
                  > > 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
                  > >[color=darkred]
                  > >> 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
                  > >>[/color]
                  > >
                  > >[/color]
                  >
                  >
                  >[/color]

                  Comment

                  • Dennis

                    #10
                    Re: VB. NET Shared Sub Main()

                    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:
                    [color=blue]
                    > 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" <notmyfirstname @planet.nl> wrote in message
                    > news:%2344dWo7q EHA.2604@TK2MSF TNGP10.phx.gbl. ..[color=green]
                    > > 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
                    > >[color=darkred]
                    > >> 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
                    > >>[/color]
                    > >
                    > >[/color]
                    >
                    >
                    >[/color]

                    Comment

                    • Philip Rieck

                      #11
                      Re: VB. NET Shared Sub Main()

                      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


                      -
                      "Dennis" <Dennis@discuss ions.microsoft. com> wrote in message
                      news:2CF8B127-C6FD-434B-8766-392C539F2685@mi crosoft.com...[color=blue]
                      > 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:
                      >[color=green]
                      >> 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" <notmyfirstname @planet.nl> wrote in message
                      >> news:%2344dWo7q EHA.2604@TK2MSF TNGP10.phx.gbl. ..[color=darkred]
                      >> > 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
                      >> >>
                      >> >
                      >> >[/color]
                      >>
                      >>
                      >>[/color][/color]


                      Comment

                      • Philip Rieck

                        #12
                        Re: VB. NET Shared Sub Main()

                        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


                        -
                        "Dennis" <Dennis@discuss ions.microsoft. com> wrote in message
                        news:2CF8B127-C6FD-434B-8766-392C539F2685@mi crosoft.com...[color=blue]
                        > 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:
                        >[color=green]
                        >> 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" <notmyfirstname @planet.nl> wrote in message
                        >> news:%2344dWo7q EHA.2604@TK2MSF TNGP10.phx.gbl. ..[color=darkred]
                        >> > 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
                        >> >>
                        >> >
                        >> >[/color]
                        >>
                        >>
                        >>[/color][/color]


                        Comment

                        • Chris Dunaway

                          #13
                          Re: VB. NET Shared Sub Main()

                          On Wed, 6 Oct 2004 10:50:11 -0500, Philip Rieck wrote:
                          [color=blue]
                          > 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[/color]

                          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.

                          Comment

                          • Cor Ligthert

                            #14
                            Re: VB. NET Shared Sub Main()

                            Andre
                            [color=blue]
                            > 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.
                            >[/color]

                            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



                            Comment

                            • Herfried K. Wagner [MVP]

                              #15
                              Re: VB. NET Shared Sub Main()

                              "Gerry O'Brien [MVP]" <gerry dot obrien at gmail dot com> schrieb:[color=blue]
                              > 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.[/color]

                              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/>

                              Comment

                              Working...