-1

I currently have an example application written in C#, and I'd like to use code from that in my VB.NET project. Right now, the function I'm trying to copy over looks like this:

    private void Start(CardInfo networkCard, IEnumerable<int> universes)
    {
        socket = new StreamingAcnSocket(Guid.NewGuid(), "Streaming ACN Snoop");
        socket.NewPacket += new EventHandler<NewPacketEventArgs<Acn.Packets.sAcn.StreamingAcnDmxPacket>>(socket_NewPacket); //This is the line I'm having trouble with
        socket.Open(networkCard.IpAddress);

        foreach (int universe in universes)
            socket.JoinDmxUniverse(universe);

        dmxOutput = new DmxStreamer(socket);
        dmxOutput.AddUniverse(sendData.Universe);

        acnPortExplorer = new RdmNetEndPointExplorer();
        acnPortExplorer.LocalAdapter = networkCard.IpAddress;
        acnPortExplorer.NewEndpointFound += acnPortExplorer_NewEndpointFound;
        acnPortExplorer.Start();

    }

Here is the VB code I have so far:

Private Sub Start(networkCard As CardInfo, universes As IEnumerable(Of Integer))
    socket = New StreamingAcnSocket(Guid.NewGuid(), "Streaming ACN Snoop")
    ''yet to convert this line
    socket.Open(networkCard.IpAddress)

    For Each universe As Integer In universes
        socket.JoinDmxUniverse(universe)
    Next

    dmxOutput = New DmxStreamer(socket)
    dmxOutput.AddUniverse(sendData.Universe)

    acnPortExplorer = New RdmNetEndPointExplorer()
    acnPortExplorer.LocalAdapter = networkCard.IpAddress
    acnPortExplorer.NewEndpointFound += acnPortExplorer_NewEndpointFound
    acnPortExplorer.Start()

End Sub

I am trying to convert this, among other functions, to VB. I have managed to convert pretty much everything with the help of an online code converter. However, I am still unable to figure out how to convert line 4 to VB.

In case it matters, this is from the StreamingACN example project from ACN on codeplex (https://acn.codeplex.com/).

I'd appreciate any help I can get. Thanks!

lightbord
  • 143
  • 4

1 Answers1

0

If you mean this line:

socket.NewPacket += new EventHandler<NewPacketEventArgs<Acn.Packets.sAcn.StreamingAcnDmxPacket>>(socket_NewPacket);

You can do it like this:

AddHandler socket.NewPacket, AddressOf socket_NewPacket

That will attach an event handler to the socket instance forwarding the calls to the method socket_NewPacket. All the EventArgs stuff is now the concern of the method socket_NewSocket, so you should meed the signature:

Public Sub socket_NewSocket(sender As Object, args As NewPacketEventArgs(Of Acn.Packets.sAcn.StreamingAcnDmxPacket))
    ' your code goes here
End Sub
Waescher
  • 5,361
  • 3
  • 34
  • 51
  • I've made the changes, and it still gives me the error `Method 'Private Sub socket_newPacket(args As NewPacketEventArgs(Of StreamingAcnDmxPacket))' does not have a signature compatible with delegate 'Delegate Sub EventHandler(Of NewPacketEventArgs(Of StreamingAcnDmxPacket))(sender As Object, e As NewPacketEventArgs(Of StreamingAcnDmxPacket))'.` – lightbord Aug 29 '17 at 21:13
  • I forgot the obligatory `sender`. Updated. – Waescher Aug 29 '17 at 21:14