By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,495 Members | 1,186 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,495 IT Pros & Developers. It's quick & easy.

How to create an object from a string name of class

P: n/a
In VB6, There is CallByName function, in .NET there are Activator.CreateInstance but it requires a Type instead of a string name of type.

Function Activator.CreateInstance(Type) as Object

There is also CreateInstance(AssemblyName as string,ObjectTypeName as string) but it returns ObjectHandle instead Object.

Function Activator.CreateInstance(String,String) as HandleObject

Any body knows how to do it as VB6's CallByName function?

NXHOANG, Vietnam

nx*****@misa.com.vn

Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
is this what you are looking for?

http://msdn.microsoft.com/library/de...us/vblr7/html/
vafctCallByNameFunction.asp

"Nguyen Xuan Hoang" <ho*****@hn.vnn.vn> wrote in message
news:eM**************@TK2MSFTNGP12.phx.gbl...
In VB6, There is CallByName function, in .NET there are
Activator.CreateInstance but it requires a Type instead of a string name of
type.
Function Activator.CreateInstance(Type) as Object
There is also CreateInstance(AssemblyName as string,ObjectTypeName as
string) but it returns ObjectHandle instead Object.
Function Activator.CreateInstance(String,String) as HandleObject

Any body knows how to do it as VB6's CallByName function?

NXHOANG, Vietnam
nx*****@misa.com.vn
Nov 20 '05 #2

P: n/a
* "Nguyen Xuan Hoang" <ho*****@hn.vnn.vn> scripsit:
In VB6, There is CallByName function, in .NET there are Activator.CreateInstance but it requires a Type instead
of a string name of type.

Function Activator.CreateInstance(Type) as Object

There is also CreateInstance(AssemblyName as string,ObjectTypeName as string) but it returns ObjectHandle
instead Object.

Function Activator.CreateInstance(String,String) as HandleObject
\\\
Private Function CreateClassByName( _
ByVal PartialAssemblyName As String, _
ByVal QualifiedClassName As String _
) As Object
Return _
Activator.CreateInstance( _
[Assembly].LoadWithPartialName( _
PartialAssemblyName _
).GetType(QualifiedClassName) _
)
End Function
///

Usage:

\\\
Dim c As Control = _
DirectCast( _
CreateClassByName( _
"System.Windows.Forms", _
"System.Windows.Forms.Button" _
), _
Control _
)
With c
.Location = New Point(10, 10)
.Size = New Size(80, 26)
.Text = "Hello World"
End With
Me.Controls.Add(c)
///
Any body knows how to do it as VB6's CallByName function?


You can still use 'CallByName'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.