473,406 Members | 2,378 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,406 software developers and data experts.

CreateInstance problem

Hello!

I have this kind of code before:

Select Case iSelected
Case 1
obj = New CompanyCollection
Case 2
obj = New ApplicationHostedCollection
End Select

A certain object is created depending on the selected number. However,
I would need to put the object names into a database, so
CompanyCollection and ApplicationHostedCollection is now saved in the
DB and accessed as a string value.

Im not sure how to create an instance of an object if the object name
to be created is a string variable.

I tried this but its not working

Dim strobj As String
strobj = "NPRG.Corelib.CompanyCollection, NPRG.Corelib"
Dim s As System.Type
s = Type.GetType(strobj, True)
Dim obj As Object
obj = Activator.CreateInstance(s)

The Type.GetType returns nothing so I cant move on. Am I doing
something wrong?

Please anyone help.

Thank you very much!

Mayet

Jan 11 '06 #1
2 1307
No, you aren't

The only thing I can guess is that you don't have the proper classname or
assembly name. Are you sure the assembly is referenced by the project?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
<ma******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hello!

I have this kind of code before:

Select Case iSelected
Case 1
obj = New CompanyCollection
Case 2
obj = New ApplicationHostedCollection
End Select

A certain object is created depending on the selected number. However,
I would need to put the object names into a database, so
CompanyCollection and ApplicationHostedCollection is now saved in the
DB and accessed as a string value.

Im not sure how to create an instance of an object if the object name
to be created is a string variable.

I tried this but its not working

Dim strobj As String
strobj = "NPRG.Corelib.CompanyCollection, NPRG.Corelib"
Dim s As System.Type
s = Type.GetType(strobj, True)
Dim obj As Object
obj = Activator.CreateInstance(s)

The Type.GetType returns nothing so I cant move on. Am I doing
something wrong?

Please anyone help.

Thank you very much!

Mayet

Jan 11 '06 #2
Karl,
Thanks for the reply. Yes the assembly is referenced by the project.

Peter,
Can you give an example of how this method is used? Thanks!

Mayet

Jan 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: David Sworder | last post by:
Hi, I need to design a method that creates and returns a large array of objects. The problem is that the *type* of object to create isn't know until runtime. As a result, a parameter of type...
0
by: ka | last post by:
I'm implementing an IDesignerHost, for the CreateComponent method. The code below is quite standard. When loading a form, the CreateComponent works fine. However, when someone choose a control from...
15
by: Brian Rogers | last post by:
Hello everyone, I apologize for the cross and re-post, but I am still searching for an answer. Why can C++ can create this object, but C# can't? I am trying to create an instance of the...
2
by: Frank Pleyer via .NET 247 | last post by:
Hi, I got the following problem : I have an defined an Array of different Actions: public PRootActions AllActions = new PRootActions ; I got a dynamic method where all Actions or other...
1
by: John Jenkins | last post by:
Hi, I have a fairly simeple question. What are the differences between Assembly.CreateInstance and System.Activator.CreateInstance? I had read that one maps to the other, however when I use...
3
by: Doug Riley | last post by:
I am using CreateInstance to create an instance of a class and invoke a function of that class. I really need it to execute in a single line of code (long story, but I want to execute this code in...
4
by: Shane | last post by:
I am having a problem where I create an instance of a class from an assembly and I try to cast it to an interface that it inherits from and it says that the cast is invalid. Here is the code: ...
2
by: vinoth | last post by:
Hi, I want to create an Instance of Class using Assembly.CreateInstance method. I have loaded my assmbly Assembly exeAssmb = Assembly.LoadWithPartialName"CommonStructures"); //Assembly...
8
by: Dan Holmes | last post by:
Isn't CreateInstance(typeof(int)) the same as CreateInstance<int>()? i don't understand how this method helps anything. dan
0
by: xievvv | last post by:
I'm working on a COM add-in project for Office. Because I don't want the overheard of VSTO, I'm going with the approach of using a C++ shim, as created by the wizard provided by MS for generating...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.