Dynamic call .net object

T

Tom

Can I dynamic call vb.net object

such like vb6 as sample

dim A as object
set a = createobject("myobject.test")
a.open()

now mypbject.test is create vb.net . How can I dynamic call without use
reference method.

Thanks
 
H

Herfried K. Wagner [MVP]

Tom said:
now mypbject.test is create vb.net . How can I dynamic call
without use reference method.

\\\
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)
///
 
T

Tom

Hi All
Thanks

However, I want to create the vbproject . One vb project (type is windows
application .exe) dynamic call another vbproject (class libary .dll) . while
windows application project do not need add reference "class libary ".
I use VB6 as example:
I create standard exe name "myApp" with the form "frmtest" . In this
frmtest. I create the button name "cmdBtn"
Meanwhile I create activex dll name "classLibs" with the class Name
"myClass". In this myClass. I create the method "HelloWorld".


In Vb6 syntax. I just do the follow :

Private Sub Command1_Click()
Dim O as object
set O = createobject("classLibs.myClass")
O.HelloWorld
End Sub

Now , Both myApp and classLibs is a .net component . I don't need convert
them into activex com. Just want to dynamic call.
How you help me above this ?

Thanks and many thanks




Herfried K. Wagner said:
Tom said:
now mypbject.test is create vb.net . How can I dynamic call
without use reference method.

\\\
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)
///
 

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

Top