473,327 Members | 1,976 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,327 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 1305
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.