Where is Sub New

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • active

    #1

    Where is Sub New

    I have a couple of projects in the VS2005 format using Partial Class.
    I can't find where the code for sub New is stored.

    Can you tell me where it is?


    thanks


  • RobinS

    #2
    Re: Where is Sub New

    There is a default constructor provided by .Net. If you don't see one, then
    that's what's being used. You can just add your own to your class, and it
    will use yours instead of the default. Also, if you add any constructors,
    ..Net assumes you will create all constructors that you want, and will not
    create a default one behind the scenes.

    Robin S.
    ----------------------------
    " active" <activeNOSPAM @a-znet.comwrote in message
    news:uI7lKs3WHH A.896@TK2MSFTNG P05.phx.gbl...
    >I have a couple of projects in the VS2005 format using Partial Class.
    I can't find where the code for sub New is stored.
    >
    Can you tell me where it is?
    >
    >
    thanks
    >

    Comment

    • active

      #3
      Re: Where is Sub New

      Maybe this solves a problem I had a while ago.

      If the constructor can have arguments.

      I needed the constructor to have arguments so that the calling form could
      set some properties before Initialize was run.

      I can't quite see how the Ide can handle a constructor with arguments but
      I'll play with it.

      Thanks again

      "RobinS" <RobinS@NoSpam. yah.nonewrote in message
      news:xcKdnV6oXs YkY3jYnZ2dnUVZ_ tKjnZ2d@comcast .com...
      There is a default constructor provided by .Net. If you don't see one,
      then that's what's being used. You can just add your own to your class,
      and it will use yours instead of the default. Also, if you add any
      constructors, .Net assumes you will create all constructors that you want,
      and will not create a default one behind the scenes.
      >
      Robin S.
      ----------------------------
      " active" <activeNOSPAM @a-znet.comwrote in message
      news:uI7lKs3WHH A.896@TK2MSFTNG P05.phx.gbl...
      >>I have a couple of projects in the VS2005 format using Partial Class.
      >I can't find where the code for sub New is stored.
      >>
      >Can you tell me where it is?
      >>
      >>
      >thanks
      >>
      >
      >

      Comment

      • rowe_newsgroups

        #4
        Re: Where is Sub New

        I can't quite see how the Ide can handle a constructor with arguments

        The only time it causes any troubles is if it is a control/component
        that is added to a form/usercontrol in designer mode. In that case the
        designer won't know what to do since it can't specify the parameters.
        You should be able to manually edit the designer generated code is the
        easiest way to cope with this. (but be warned it can/will overwrite
        your changes when it wants to).

        Thanks,

        Seth Rowe


        On Mar 1, 10:16 am, " active" <activeNOS... @a-znet.comwrote:
        Maybe this solves a problem I had a while ago.
        >
        If the constructor can have arguments.
        >
        I needed the constructor to have arguments so that the calling form could
        set some properties before Initialize was run.
        >
        I can't quite see how the Ide can handle a constructor with arguments but
        I'll play with it.
        >
        Thanks again
        >
        "RobinS" <Rob...@NoSpam. yah.nonewrote in message
        >
        news:xcKdnV6oXs YkY3jYnZ2dnUVZ_ tKjnZ2d@comcast .com...
        >
        There is a default constructor provided by .Net. If you don't see one,
        then that's what's being used. You can just add your own to your class,
        and it will use yours instead of the default. Also, if you add any
        constructors, .Net assumes you will create all constructors that you want,
        and will not create a default one behind the scenes.
        >
        Robin S.
        ----------------------------
        " active" <activeNOS... @a-znet.comwrote in message
        news:uI7lKs3WHH A.896@TK2MSFTNG P05.phx.gbl...
        >I have a couple of projects in the VS2005 format using Partial Class.
        I can't find where the code for sub New is stored.
        >
        Can you tell me where it is?
        >
        thanks

        Comment

        • active

          #5
          Re: Where is Sub New

          I tried this with a vs2003 style project and it seems to work OK.

          Public Sub New(ByVal test As String)

          MyBase.New()

          InitializeCompo nent()

          Text = test

          That is, when I run it the form's text displays what the caller set the
          parameter to.

          I cunfused about what the Ide does.

          I changed the last line to

          Text = "MORE JUNK"

          But again the IDE did not display it.

          It does create an instance of the class doesn't it?

          Could it be that Net develops a constructor with no arguments if I don't?

          Thanks



          I'm thinking about redoing that app since it would be so much neater an less
          error prone this way but it would not be a trivial change so I want to be
          sure before I start.

          I trying to think of other tests but have not come up with anything yet.



          "RobinS" <RobinS@NoSpam. yah.nonewrote in message
          news:xcKdnV6oXs YkY3jYnZ2dnUVZ_ tKjnZ2d@comcast .com...
          There is a default constructor provided by .Net. If you don't see one,
          then that's what's being used. You can just add your own to your class,
          and it will use yours instead of the default. Also, if you add any
          constructors, .Net assumes you will create all constructors that you want,
          and will not create a default one behind the scenes.
          >
          Robin S.
          ----------------------------
          " active" <activeNOSPAM @a-znet.comwrote in message
          news:uI7lKs3WHH A.896@TK2MSFTNG P05.phx.gbl...
          >>I have a couple of projects in the VS2005 format using Partial Class.
          >I can't find where the code for sub New is stored.
          >>
          >Can you tell me where it is?
          >>
          >>
          >thanks
          >>
          >
          >

          Comment

          • active

            #6
            Re: Where is Sub New

            I ran a simple test with a form and the Ide seemed to ignore my constructor
            when it displayed the form. I can't figure what it is doing.

            Why is it OK with a Form but not with a control/component ?

            I was hoping the designer would do something like supply all empty arguments
            or something like that.

            Thanks for the help

            "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
            news:1172764968 .044775.178270@ p10g2000cwp.goo glegroups.com.. .
            >I can't quite see how the Ide can handle a constructor with arguments
            >
            The only time it causes any troubles is if it is a control/component
            that is added to a form/usercontrol in designer mode. In that case the
            designer won't know what to do since it can't specify the parameters.
            You should be able to manually edit the designer generated code is the
            easiest way to cope with this. (but be warned it can/will overwrite
            your changes when it wants to).
            >
            Thanks,
            >
            Seth Rowe
            >
            >
            On Mar 1, 10:16 am, " active" <activeNOS... @a-znet.comwrote:
            >Maybe this solves a problem I had a while ago.
            >>
            >If the constructor can have arguments.
            >>
            >I needed the constructor to have arguments so that the calling form could
            >set some properties before Initialize was run.
            >>
            >I can't quite see how the Ide can handle a constructor with arguments but
            >I'll play with it.
            >>
            >Thanks again
            >>
            >"RobinS" <Rob...@NoSpam. yah.nonewrote in message
            >>
            >news:xcKdnV6oX sYkY3jYnZ2dnUVZ _tKjnZ2d@comcas t.com...
            >>
            There is a default constructor provided by .Net. If you don't see one,
            then that's what's being used. You can just add your own to your class,
            and it will use yours instead of the default. Also, if you add any
            constructors, .Net assumes you will create all constructors that you
            want,
            and will not create a default one behind the scenes.
            >>
            Robin S.
            ----------------------------
            " active" <activeNOS... @a-znet.comwrote in message
            >news:uI7lKs3WH HA.896@TK2MSFTN GP05.phx.gbl...
            >>I have a couple of projects in the VS2005 format using Partial Class.
            >I can't find where the code for sub New is stored.
            >>
            >Can you tell me where it is?
            >>
            >thanks
            >
            >

            Comment

            • RobinS

              #7
              Re: Where is Sub New

              I don't think .Net provides a default constructor if you provide a
              non-default one. So how is it instantiating? I don't know, maybe I'm wrong.
              If I didn't want anybody to be able to create this form without providing
              the input string, I would add a default constructor and make it private.

              If you want your main form to have a string passed in to it, you can't have
              the startup object be a form. You have to make a sub main and instantiate
              and show your form from there.

              Robin S.
              -------------------------------
              " active" <activeNOSPAM @a-znet.comwrote in message
              news:%23U4Z$GCX HHA.4240@TK2MSF TNGP06.phx.gbl. ..
              >I tried this with a vs2003 style project and it seems to work OK.
              >
              Public Sub New(ByVal test As String)
              >
              MyBase.New()
              >
              InitializeCompo nent()
              >
              Text = test
              >
              That is, when I run it the form's text displays what the caller set the
              parameter to.
              >
              I cunfused about what the Ide does.
              >
              I changed the last line to
              >
              Text = "MORE JUNK"
              >
              But again the IDE did not display it.
              >
              It does create an instance of the class doesn't it?
              >
              Could it be that Net develops a constructor with no arguments if I don't?
              >
              Thanks
              >
              >
              >
              I'm thinking about redoing that app since it would be so much neater an
              less error prone this way but it would not be a trivial change so I want
              to be sure before I start.
              >
              I trying to think of other tests but have not come up with anything yet.
              >
              >
              >
              "RobinS" <RobinS@NoSpam. yah.nonewrote in message
              news:xcKdnV6oXs YkY3jYnZ2dnUVZ_ tKjnZ2d@comcast .com...
              >There is a default constructor provided by .Net. If you don't see one,
              >then that's what's being used. You can just add your own to your class,
              >and it will use yours instead of the default. Also, if you add any
              >constructors , .Net assumes you will create all constructors that you
              >want, and will not create a default one behind the scenes.
              >>
              >Robin S.
              >----------------------------
              >" active" <activeNOSPAM @a-znet.comwrote in message
              >news:uI7lKs3WH HA.896@TK2MSFTN GP05.phx.gbl...
              >>>I have a couple of projects in the VS2005 format using Partial Class.
              >>I can't find where the code for sub New is stored.
              >>>
              >>Can you tell me where it is?
              >>>
              >>>
              >>thanks
              >>>
              >>
              >>
              >
              >

              Comment

              • rowe_newsgroups

                #8
                Re: Where is Sub New

                On Mar 1, 11:31 am, " active" <activeNOS... @a-znet.comwrote:
                I tried this with a vs2003 style project and it seems to work OK.
                >
                Public Sub New(ByVal test As String)
                >
                MyBase.New()
                >
                InitializeCompo nent()
                >
                Text = test
                >
                That is, when I run it the form's text displays what the caller set the
                parameter to.
                >
                I cunfused about what the Ide does.
                >
                I changed the last line to
                >
                Text = "MORE JUNK"
                >
                But again the IDE did not display it.
                >
                It does create an instance of the class doesn't it?
                >
                Could it be that Net develops a constructor with no arguments if I don't?
                >
                Thanks
                >
                I'm thinking about redoing that app since it would be so much neater an less
                error prone this way but it would not be a trivial change so I want to be
                sure before I start.
                >
                I trying to think of other tests but have not come up with anything yet.
                >
                "RobinS" <Rob...@NoSpam. yah.nonewrote in message
                >
                news:xcKdnV6oXs YkY3jYnZ2dnUVZ_ tKjnZ2d@comcast .com...
                >
                There is a default constructor provided by .Net. If you don't see one,
                then that's what's being used. You can just add your own to your class,
                and it will use yours instead of the default. Also, if you add any
                constructors, .Net assumes you will create all constructors that you want,
                and will not create a default one behind the scenes.
                >
                Robin S.
                ----------------------------
                " active" <activeNOS... @a-znet.comwrote in message
                news:uI7lKs3WHH A.896@TK2MSFTNG P05.phx.gbl...
                >I have a couple of projects in the VS2005 format using Partial Class.
                I can't find where the code for sub New is stored.
                >
                Can you tell me where it is?
                >
                thanks
                Make sure there is no constructor defined in the designer.vb file for
                your form. Sometimes the ide will add the constructor there. Also,
                just press F8 to start stepping through the code and see if a
                different constructor is being called than your parameterized one.

                Thanks,

                Seth Rowe

                Comment

                • RobinS

                  #9
                  Re: Where is Sub New

                  That pesky designer code... ;-)

                  Robin S.
                  ----------------------------
                  "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
                  news:1172772091 .264986.91480@n 33g2000cwc.goog legroups.com...
                  On Mar 1, 11:31 am, " active" <activeNOS... @a-znet.comwrote:
                  >I tried this with a vs2003 style project and it seems to work OK.
                  >>
                  >Public Sub New(ByVal test As String)
                  >>
                  >MyBase.New()
                  >>
                  >InitializeComp onent()
                  >>
                  >Text = test
                  >>
                  >That is, when I run it the form's text displays what the caller set the
                  >parameter to.
                  >>
                  >I cunfused about what the Ide does.
                  >>
                  >I changed the last line to
                  >>
                  >Text = "MORE JUNK"
                  >>
                  >But again the IDE did not display it.
                  >>
                  >It does create an instance of the class doesn't it?
                  >>
                  >Could it be that Net develops a constructor with no arguments if I
                  >don't?
                  >>
                  >Thanks
                  >>
                  >I'm thinking about redoing that app since it would be so much neater an
                  >less
                  >error prone this way but it would not be a trivial change so I want to
                  >be
                  >sure before I start.
                  >>
                  >I trying to think of other tests but have not come up with anything yet.
                  >>
                  >"RobinS" <Rob...@NoSpam. yah.nonewrote in message
                  >>
                  >news:xcKdnV6oX sYkY3jYnZ2dnUVZ _tKjnZ2d@comcas t.com...
                  >>
                  There is a default constructor provided by .Net. If you don't see one,
                  then that's what's being used. You can just add your own to your
                  class,
                  and it will use yours instead of the default. Also, if you add any
                  constructors, .Net assumes you will create all constructors that you
                  want,
                  and will not create a default one behind the scenes.
                  >>
                  Robin S.
                  ----------------------------
                  " active" <activeNOS... @a-znet.comwrote in message
                  >news:uI7lKs3WH HA.896@TK2MSFTN GP05.phx.gbl...
                  >>I have a couple of projects in the VS2005 format using Partial Class.
                  >I can't find where the code for sub New is stored.
                  >>
                  >Can you tell me where it is?
                  >>
                  >thanks
                  >
                  Make sure there is no constructor defined in the designer.vb file for
                  your form. Sometimes the ide will add the constructor there. Also,
                  just press F8 to start stepping through the code and see if a
                  different constructor is being called than your parameterized one.
                  >
                  Thanks,
                  >
                  Seth Rowe
                  >

                  Comment

                  • active

                    #10
                    Re: Where is Sub New


                    "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
                    news:1172772091 .264986.91480@n 33g2000cwc.goog legroups.com...
                    On Mar 1, 11:31 am, " active" <activeNOS... @a-znet.comwrote:
                    >I tried this with a vs2003 style project and it seems to work OK.
                    >>
                    >Public Sub New(ByVal test As String)
                    >>
                    >MyBase.New()
                    >>
                    >InitializeComp onent()
                    >>
                    >Text = test
                    >>
                    >That is, when I run it the form's text displays what the caller set the
                    >parameter to.
                    >>
                    >I cunfused about what the Ide does.
                    >>
                    >I changed the last line to
                    >>
                    >Text = "MORE JUNK"
                    >>
                    >But again the IDE did not display it.
                    >>
                    >It does create an instance of the class doesn't it?
                    >>
                    >Could it be that Net develops a constructor with no arguments if I don't?
                    >>
                    >Thanks
                    >>
                    >I'm thinking about redoing that app since it would be so much neater an
                    >less
                    >error prone this way but it would not be a trivial change so I want to be
                    >sure before I start.
                    >>
                    >I trying to think of other tests but have not come up with anything yet.
                    >>
                    >"RobinS" <Rob...@NoSpam. yah.nonewrote in message
                    >>
                    >news:xcKdnV6oX sYkY3jYnZ2dnUVZ _tKjnZ2d@comcas t.com...
                    >>
                    There is a default constructor provided by .Net. If you don't see one,
                    then that's what's being used. You can just add your own to your class,
                    and it will use yours instead of the default. Also, if you add any
                    constructors, .Net assumes you will create all constructors that you
                    want,
                    and will not create a default one behind the scenes.
                    >>
                    Robin S.
                    ----------------------------
                    " active" <activeNOS... @a-znet.comwrote in message
                    >news:uI7lKs3WH HA.896@TK2MSFTN GP05.phx.gbl...
                    >>I have a couple of projects in the VS2005 format using Partial Class.
                    >I can't find where the code for sub New is stored.
                    >>
                    >Can you tell me where it is?
                    >>
                    >thanks
                    >
                    Make sure there is no constructor defined in the designer.vb file for
                    This is the vs2003 style project
                    your form. Sometimes the ide will add the constructor there. Also,
                    just press F8 to start stepping through the code and see if a
                    different constructor is being called than your parameterized one.
                    >
                    Thanks


                    Comment

                    • active

                      #11
                      Re: Where is Sub New

                      Thanks a lot

                      "RobinS" <RobinS@NoSpam. yah.nonewrote in message
                      news:pO6dndvZgN tEj3rYnZ2dnUVZ_ u-unZ2d@comcast.c om...
                      >I don't think .Net provides a default constructor if you provide a
                      >non-default one. So how is it instantiating? I don't know, maybe I'm wrong.
                      >If I didn't want anybody to be able to create this form without providing
                      >the input string, I would add a default constructor and make it private.
                      >
                      If you want your main form to have a string passed in to it, you can't
                      have the startup object be a form. You have to make a sub main and
                      instantiate and show your form from there.
                      >
                      Robin S.
                      -------------------------------
                      " active" <activeNOSPAM @a-znet.comwrote in message
                      news:%23U4Z$GCX HHA.4240@TK2MSF TNGP06.phx.gbl. ..
                      >>I tried this with a vs2003 style project and it seems to work OK.
                      >>
                      >Public Sub New(ByVal test As String)
                      >>
                      >MyBase.New()
                      >>
                      >InitializeComp onent()
                      >>
                      >Text = test
                      >>
                      >That is, when I run it the form's text displays what the caller set the
                      >parameter to.
                      >>
                      >I cunfused about what the Ide does.
                      >>
                      >I changed the last line to
                      >>
                      >Text = "MORE JUNK"
                      >>
                      >But again the IDE did not display it.
                      >>
                      >It does create an instance of the class doesn't it?
                      >>
                      >Could it be that Net develops a constructor with no arguments if I don't?
                      >>
                      >Thanks
                      >>
                      >>
                      >>
                      >I'm thinking about redoing that app since it would be so much neater an
                      >less error prone this way but it would not be a trivial change so I want
                      >to be sure before I start.
                      >>
                      >I trying to think of other tests but have not come up with anything yet.
                      >>
                      >>
                      >>
                      >"RobinS" <RobinS@NoSpam. yah.nonewrote in message
                      >news:xcKdnV6oX sYkY3jYnZ2dnUVZ _tKjnZ2d@comcas t.com...
                      >>There is a default constructor provided by .Net. If you don't see one,
                      >>then that's what's being used. You can just add your own to your class,
                      >>and it will use yours instead of the default. Also, if you add any
                      >>constructor s, .Net assumes you will create all constructors that you
                      >>want, and will not create a default one behind the scenes.
                      >>>
                      >>Robin S.
                      >>----------------------------
                      >>" active" <activeNOSPAM @a-znet.comwrote in message
                      >>news:uI7lKs3W HHA.896@TK2MSFT NGP05.phx.gbl.. .
                      >>>>I have a couple of projects in the VS2005 format using Partial Class.
                      >>>I can't find where the code for sub New is stored.
                      >>>>
                      >>>Can you tell me where it is?
                      >>>>
                      >>>>
                      >>>thanks
                      >>>>
                      >>>
                      >>>
                      >>
                      >>
                      >
                      >

                      Comment

                      Working...