473,378 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

To create an instance of class in VB2005

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
2 1582
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Steven.Xu | last post by:
Hello everyone! I have a problem about create an instance automatically in C#. Now I have a class: namespace1.namespace11.CClass01. I want to create it's instance in a function named...
4
by: Ray | last post by:
I want to dynamically load DLLs (created from VB) and instantiate a class with a particular name, like "ProcessClass". I am able to load the DLL and confirm there is a class by that name BUT I...
4
by: Joe HM | last post by:
Hello - I have a Base Class where I want a New() implemented that can be called from the outside. This New() should create an instance of the appropriate cDerivedX Class ... The following...
4
by: R. Nachtsturm | last post by:
Hi, Question (in short): can i somehow use the namespace tag to define that a class in its own file is actually the subclass (namespace wise) of another class? Explanation: for example, if I...
2
by: swartzbill2000 | last post by:
I want to PostMessage from a class instance to its containing form. I want the WPARAM to point to the class instance. I am using the declaration of PostMessage from www.pinvoke.net. WPARAM is an...
2
by: Angel Of Death | last post by:
I have a method. It takes some XML as a parameter. Depending on the content of the XML it should create a specific object and call a KNOWN method. So: public void PersistXml(string XmlData){} ...
3
by: Rich | last post by:
I put together a simple test class libary (VB2005) with one class and one function that takes an integer argument and adds 10 the argument and returns that number. Then I created a simple VB2005...
27
by: max | last post by:
Hello, I am a newbye, and I'm trying to write a simple application. I have five tables with three columns; all tables are identical; I need to change some data in the first table and let VB...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, I have Visual Studio 2005 Professional. I have been deploying VB2005 apps using "Click Once" which works great and will add .Net 2.0 framework where needed and adds all prerequisite...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.