VB Create object from string

  • Thread starter Thread starter Shawn
  • Start date Start date
S

Shawn

Hi

I have several reports that are in my web project. I
have the names of the reports and class names in a
database. For example,

Report Name
Product Report

Class Name
ProductReport

These are Crystal reports in my project. When the user
generates a report, I have to create a new instance of
the report object (Private myReport as New
ProductReport). How can I declare my report objects from
strings if I load the object names from the database
(Private myReport as new "ProductReport")

Shawn
 
Assuming these classes live inside the same assembly, you can use the
Activator class to do this:

MyClass p = (MyClass)
Activator.CreateInstance(Assembly.GetExecutingAssembly().GetType("MyNamespac
e.MyClass", true, true));

This is C# of course but you get the idea.
 
Back
Top