2 Replies - 1252 Views - Last Post: 02 January 2011 - 07:56 AM Rate Topic: -----

#1 Ameel  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 19-June 08

Code conversion, c# to vb .ne

Posted 02 January 2011 - 06:20 AM

Hi guys, I'm having troubles converting the code below from c# to vb .net:
			if (rcvPack==null) 
			{
				rcvPack=new dotnetWinpCap.ReceivePacket(this.ReceivePacket);
				wpcap.OnReceivePacket+=rcvPack;
			}



I ran it through http://www.developer...t/csharp-to-vb/ and got:
        If rcvPack Is Nothing Then
            rcvPack = New dotnetWinpCap.ReceivePacket(Me.ReceivePacket)
            wpcap.OnReceivePacket += rcvPack
        End If



but i get 2 following errors
Delegate 'dotnetWinpCap.ReceivePacket' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor

'Public Event OnReceivePacket(sender As Object, p As PacketHeader, s() As Byte)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.



Any help/insight?

Cheers

Is This A Good Question/Topic? 0
  • +

Replies To: Code conversion, c# to vb .ne

#2 Ameel  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 19-June 08

Re: Code conversion, c# to vb .ne

Posted 02 January 2011 - 06:29 AM

Correct me if i'm wrong, but is this ok:
rcvPack = New dotnetWinpCap.ReceivePacket(AddressOf ReceivePacket)


instead of
rcvPack = New dotnetWinpCap.ReceivePacket(Me.ReceivePacket)



What about the 2nd part?

Cheers
Was This Post Helpful? 0
  • +
  • -

#3 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1067
  • View blog
  • Posts: 4,176
  • Joined: 02-July 08

Re: Code conversion, c# to vb .ne

Posted 02 January 2011 - 07:56 AM

1) If New dotnetWinpCap.ReceivePacket is the delegate(and it looks like it, then yes.
2) this is an event, and if there setting up the delegate for the other event then I would think you use the Addhandler here for this and AddressOf to the one above. Just because it does not look like the place to Raise this event. Could you show or tell us where this code is in respect to where the program is and what it is doing?

If rcvPack Is Nothing Then
    rcvPack = New dotnetWinpCap.ReceivePacket(AddressOf Me.ReceivePacket)
    Addhandler wpcap.OnReceivePacket, AddressOf Me.ReceivePacket 'or other sub you want
End If

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1