0

I have an interface IView:

 Option Explicit

Public Event OnClientSelected()

Public Property Get ClientNames() As Variant
End Property
(...)

But I am not able to implement the event in my user form. Properties and subs are allowed to implement, but event not.

Is it possible to make interface implementation with events?

Tipejn
  • 1
  • Did you declare the IView object in the form WithEvents? – Vincent G Feb 27 '19 at 13:29
  • I want the form to be an implementation of the interface, so I don't have IView object. I use: Implements IView – Tipejn Feb 27 '19 at 13:32
  • 1
    An [MCVE](https://stackoverflow.com/help/mcve) would be nice. I don't think you can directly have event handling and inteface (WithEvents and Implements). See https://stackoverflow.com/questions/41023670/can-we-use-interfaces-and-events-together-at-the-same-time – Vincent G Feb 27 '19 at 13:43
  • No, it isn't possible. The best way to verify this is by not implementing the `Event` along with the rest of the interface. This still compiles - if the `Event` was considered part of the interface you'd get a compile error. – Comintern Feb 27 '19 at 13:50

1 Answers1

-1

Did you use withevents?

I've done the following, added a test function to your class

Private WithEvents iface As clsIface

Private Sub UserForm_Initialize()
    Set iface = New clsIface
End Sub

Private Sub iface_OnClientSelected()
    '   Event subscription
End Sub

Private Sub UserForm_Click()
    iface.test
End Sub

Function added to class

Public Function test()
    RaiseEvent OnClientSelected
End Function
Nathan_Sav
  • 8,466
  • 2
  • 13
  • 20