By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

To create an instance of class in VB2005

P: n/a
Hello,

I need to create with VB2005 an instance of one of the classes of the
project in run time.

For example:

- The Namespace root and the name of the project are he himself: "Project"
- The project has including three class: Class_1.vb, Class_2.vb and
Class_3.vb

In VB2003 it did of the following way:

Dim NameClass as string ="Class_1"
Dim Ensam as Type = Type.GetType("Project" & Chr(46) & NameClass)
Dim result as Object = Activator.CreateInstance(Ensam)
As it would have to do it in VB2005?
if I execute the Type Ensam is Nothing

Thanks!
Jordi
Oct 31 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Jordi Julią wrote:
Hello,

I need to create with VB2005 an instance of one of the classes of the
project in run time.

For example:

- The Namespace root and the name of the project are he himself: "Project"
- The project has including three class: Class_1.vb, Class_2.vb and
Class_3.vb

In VB2003 it did of the following way:

Dim NameClass as string ="Class_1"
Dim Ensam as Type = Type.GetType("Project" & Chr(46) & NameClass)
Dim result as Object = Activator.CreateInstance(Ensam)
As it would have to do it in VB2005?
if I execute the Type Ensam is Nothing
The above works for me - are you sure your classes haven't got
themselves nested inside some other class?

Try creating an instance of one directly and see what Type it thinks it is:

Dim c2 as New Class_2

Debug.Writeline( c2.GetType().ToString() )

HTH,
Phill W.
Nov 2 '06 #2

P: n/a
Hello,

I have proven what you have said to me and:

Dim c2 As New Class_2 '(Class_2 exist in
Project)
dim Name as string = c2.GetType().ToString 'Name="Project.c2"
Dim ensam As Type = Type.GetType(Name) 'ensam = Nothing
Because 'ensam' Nothing has left?

Thanks!


"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kescribió en el mensaje
news:ei**********@south.jnrs.ja.net...
Jordi Julią wrote:
>Hello,

I need to create with VB2005 an instance of one of the classes of the
project in run time.

For example:

- The Namespace root and the name of the project are he himself:
"Project"
- The project has including three class: Class_1.vb, Class_2.vb and
Class_3.vb

In VB2003 it did of the following way:

Dim NameClass as string ="Class_1"
Dim Ensam as Type = Type.GetType("Project" & Chr(46) & NameClass)
Dim result as Object = Activator.CreateInstance(Ensam)
As it would have to do it in VB2005?
if I execute the Type Ensam is Nothing

The above works for me - are you sure your classes haven't got themselves
nested inside some other class?

Try creating an instance of one directly and see what Type it thinks it
is:

Dim c2 as New Class_2

Debug.Writeline( c2.GetType().ToString() )

HTH,
Phill W.

Nov 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.