.NETGURU
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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification