Search:
Namespaces
Discussions
.NET v1.1
Feedback
How to add event handler in VBA?
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.framework.interop
.
Post a new message to this list...
Nicola Garone
Hi all,
I have a library with some controls developed with VB.Net which I've
used for a while, now I've added an event to signal some data is changed,
but I can't find how to add event handler in the host application (VB6).
I can see regasm has automatically added a method add_<eventname> to my
control, and a type <eventname>eventhandler is now defined in my VBA
application, but I don't know the syntax to add the function handler...
Here is some code
********VB.net code
Public Interface iMyControl
Event DataChanged()
' some others properties and methods
End Interface
Class MyControl
' class initializzation omitted....
Implements iMyControl
Event DataChanged() Implements iMyControl.DataChanged
' others properties and methods implemented here
Public Event DataChanged
' code
' code
' code
Private Sub Edit()
' some code....
' if data is modified bDataChanged is set to true
If bDataChanged Then RaiseEvent DataChanged()
End Sub
End Class
End Namespace
********VBA
Public myCtrl As SomeApp.iMyControl
Sub Test()
Set myCtrl = New SomeApp.MyControl
myCtrl.add_DataChanged(myHandler) ' this is wrong I know but which is
the right way?
' some code use the control...
End Sub
Sub myHandler() as DataChanghedEventHandler
MsgBox "The data is changed !"
End Sub
Who can help?
Thanks!
Nicola
Reply to this message...
Christian Fröschlin
Nicola Garone wrote:
[Original message clipped]
The syntax in VB6 would be something like this:
Private WithEvents myCtrl As SomeApp.iMyControl
....
Set myCtrl = New SomeApp.MyControl
....
Private Sub myCtrl_DataChanged()
'Handler code
...
End Sub
However, I don't think that the event passes
from .NET to COM quite that easily. Try adding
some attributes to the declarations, e.g.
<InterfaceTypeAttribute(
ComInterfaceType
.InterfaceIsIDispatch)>
to iMyControl and
<ClassInterface(
ClassInterfaceType
.None), _
ComSourceInterfaces("SomeApp.iMyControl")> _
to MyControl
Reply to this message...
System.Runtime.InteropServices.ClassInterfaceType
System.Runtime.InteropServices.ComInterfaceType
System.Runtime.InteropServices.InterfaceTypeAttribute
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com