dot NET DLL for use with VBA - Reference the vba created class within the C# class? (specifically an event)
"Notify" and is an event that shows up and works fine in vba.
I tried to add a function called "Start() in csharp that calls the EVENT "Notify()" of the class that was instantiated from vba.
How to fire that event?
Given the following code:
----VBA----
Private WithEvents c As Myclass
Private Sub Command_Click()
Set c = New Myclass
c.setSecurityFilePath ("NEWPATH!")
c.Start
End Sub
Private Sub c_Notify(ByVal s As String)
MsgBox s
End Sub
-----C Sharp------
public delegate void NotifyDelegate(string s);
[GuidAttribute("SOMEGUID")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface INotifyEvents
{
[DispId(1)]
void Notify(string s);
}
[ComSourceInterfaces(typeof(INotifyEvents))]
[ComVisible(true), GuidAttribute("SOMEGUID")]
[ProgId("clsMyclass.Myclass")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Myclass
public delegate void NotifyDelegate(string s);
[GuidAttribute("SOMEGUID")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface INotifyEvents
{
[DispId(1)]
void Notify(string s);
}
public class MyClass
{
[ComVisible(true)]
public void setSecurityFilePath(string p)
{
secpath = p;
Notify("SecurityFilePath set to: "+ p); << this works fine, fires the event in vba!
}
[ComVisible(true)]
static async Task Start()
{
this.Notify("HELLO FROM THE DLL") << (Compiler Error CS0026) Keyword 'this' is not valid in a static property, static method, or static field initializer
}
}