PC Review


Reply
Thread Tools Rate Thread

Create Instance of a Class from ClassName

 
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      26th Nov 2004
I want to pass a variable to a Procedure and have that function instantiate
an instance of that class. For example, I have a Class named "myClass":

CreateInstance ("myClass")

Sub CreateInstance (classname as string)
Dim newinstance as classname
.....
End Sub

Is there anyway that I can do this?
--
Dennis in Houston
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TmlnZWwgQXJtc3Ryb25n?=
Guest
Posts: n/a
 
      26th Nov 2004
Hi Dennis

Try Activator.CreateInstanceFrom - that should do the trick for you.

HTH

Nigel Armstrong

"Dennis" wrote:

> I want to pass a variable to a Procedure and have that function instantiate
> an instance of that class. For example, I have a Class named "myClass":
>
> CreateInstance ("myClass")
>
> Sub CreateInstance (classname as string)
> Dim newinstance as classname
> .....
> End Sub
>
> Is there anyway that I can do this?
> --
> Dennis in Houston

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      26th Nov 2004
Dennis,

When you do this, than are programlanguages as VBA or JS the best for that.

However VBNet is made to create good working executes in runtime.

Just my thought

Cor


"Dennis" <(E-Mail Removed)>

>I want to pass a variable to a Procedure and have that function instantiate
> an instance of that class. For example, I have a Class named "myClass":
>
> CreateInstance ("myClass")
>
> Sub CreateInstance (classname as string)
> Dim newinstance as classname
> .....
> End Sub
>
> Is there anyway that I can do this?
> --
> Dennis in Houston



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamically create class instance from class name Scott Izu Microsoft C# .NET 1 7th Oct 2008 03:20 PM
how to create class instance? André Microsoft VB .NET 4 15th Mar 2007 05:20 PM
How to create an instance of a vb.net class from vc++ S Wheeler Microsoft VC .NET 9 29th Jan 2006 07:47 PM
How to have New() in a Base Class create and return an instance of a Derived Class? Joe HM Microsoft VB .NET 4 22nd Nov 2005 09:31 PM
Activator could not create a instance of the class as the Length of the class name is 36 characters Jack Wright Microsoft C# .NET 0 18th Mar 2004 04:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:23 AM.