CreateInstance problem

M

mayetski

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
 
K

Karl Seguin [MVP]

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
 
M

mayetski

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top