title: Handling events exposed on a .NET class via COM in VB6
body: <p>Handling events exposed on a .NET class via COM in VB6</p>
  
  <p>My test .NET (class libary registered for interop in compiler settings) code:</p>
  
  <pre><code>Imports System.Runtime.InteropServices
  
  &lt;InterfaceType(ComInterfaceType.InterfaceIsIDispatch), ComVisible(True)&gt; _
  Public Interface MyEventInterface
      &lt;DispId(1)&gt; Event Exploded(ByVal Text As String)
      &lt;DispId(2)&gt; Sub PushRedButton()
  End Interface
  
  
  &lt;ClassInterface(ClassInterfaceType.None)&gt; _
  Public Class EventTest
      Implements MyEventInterface
  
      Public Event Exploded(ByVal Text As String) Implements MyEventInterface.Exploded
  
      Public Sub PushRedButton() Implements MyEventInterface.PushRedButton
  
          RaiseEvent Exploded("Bang")
  
      End Sub
  
  End Class
  </code></pre>
  
  <p>My test VB6 application winforms code (which references the above class libary):</p>
  
  <pre><code>Public ct As New ComTest1.EventTest
  
  Private Sub Command1_Click()
  
      ct.add_Exploded (ExplodedHandler)
  
      ct.PushRedButton
  
      ct.remove_Exploded (ExplodedHandler)
  
  End Sub
  
  Private Sub ExplodedHandler(ByVal Text As String)
  
      MsgBox Text
  
  End Sub
  </code></pre>
  
  <p>Specifially I'm not sure how to set up the handler in VB6 the compile error I get is "Argument not optional" on this line in the VB6:</p>
  
  <pre><code>ct.add_Exploded (ExplodedHandler)
  </code></pre>