Where is Sub New

  • Thread starter Thread starter active
  • Start date Start date
A

active

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
 
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.
 
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
 
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
 
I tried this with a vs2003 style project and it seems to work OK.

Public Sub New(ByVal test As String)

MyBase.New()

InitializeComponent()

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.
 
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
 
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.
-------------------------------
 
I tried this with a vs2003 style project and it seems to work OK.

Public Sub New(ByVal test As String)

MyBase.New()

InitializeComponent()

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.

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
 
rowe_newsgroups said:
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
 
Thanks a lot

RobinS said:
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.
 
Back
Top