class from string

K

kresimir ivkovic

Dear all Guru's

How can I references on class with string ????

Sample like that but ???:

stringRef = "Appl.Main"
Dim someClassX as "Appl.Main"

Thanx for any suggestion

K.I.
 
P

Pavel Minaev

Dear all Guru's

How can I references on class with string ????

Sample like that but ???:

stringRef = "Appl.Main"
Dim someClassX as "Appl.Main"

You cannot. A type of a variable (or function parameter) in VB is a
compile-time construct. You can create an object of some type which
name is stored in a string at run-time, though:

Dim obj As Object = Activator.CreateInstance(Type.GetType
("Appl.Main"))

However, if you explain why you actually need that sort of thing, it
is very likely that a better design would avoid a need for this kind
of thing.
 

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

Similar Threads

GCHandle.Alloc 2
Big PICA 1
Problem with custom message class 1
Create class from name 5
Problem with custom form displaying 1
update label on form from within class file 5
Is that a good design? 5
LINQ to XML 1

Top