If that is all you need, use the Activator.CreateInstance() method.
It'll take either a System.Type or a string representation of a Type
"Namespace.ClassName, AssemblyName"

Adam..

> -----Original Message-----
> From: Moderated discussion of advanced .NET topics. 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> [EMAIL PROTECTED]
> Sent: Monday, March 17, 2003 1:23 PM
> To: [EMAIL PROTECTED]
> Subject: [ADVANCED-DOTNET] Scripting Engine
> 
> 
> Hi Everyone,
> 
> I need a sub that creates an instance of an object whose class name is
> passed in.
> 
> Sub CreateInstance(ByVal className as String)
>  Dim obj As New "className"() ' "className" is whatever class
> name passed in
> End Sub
> 
> I tried to use the Script Control as follows. but it throwed a
> System.Runtime.InteropServices.COMException
> 
> Sub CreateInstance(ByVal className as String)
>         Dim sc As MSScriptControl.ScriptControl
>         sc = New MSScriptControl.ScriptControlClass()
>         sc.Language = "VBScript"
>  Dim command as String = "Dim obj As New " & className & "()"
>         sc.ExecuteStatement(command)
> End Sub



DISCLAIMER:
This communication, along with any documents, files or attachments, is intended only 
for the use of the addressee and may contain legally privileged and confidential 
information. If you are not the intended recipient, you are hereby notified that any 
dissemination, distribution or copying of any information contained in or attached to 
this communication is strictly prohibited. If you have received this message in error, 
please notify the sender immediately and destroy the original communication and its 
attachments without reading, printing or saving in any manner. This communication does 
not form any contractual obligation on behalf of the sender or, the sender's employer, 
or the employer's parent company, affiliates or subsidiaries.



===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
You may be interested in Guerrilla .NET, 24 March 2003, in London and Boston
http://www.develop.com/courses/gdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to