Convert While in C# to VB.Net
I am a little stuck, I am following these examples and trying to do them in VB.Net but have run into a problem.
SharpPcap Examples
I am working on example 4 and am not sure how I would convert this to VB.Net
while( (packet=device.PcapGetNextPacket()) != null )
I have tried:
While Not (Packet = Device.PcapGetNextPacket) Is Nothing
With no go.
How would I convert this C# statement to VB.Net?
Thanks,
David
Re: Convert While in C# to VB.Net
i think this will work
While Not ((packet = device.PcapGetNextPacket) Is Nothing)
Re: Convert While in C# to VB.Net
In C# an assignment, i.e. using "=" to assign a value to a variable, returns a value, specifically the value that was assigned to the variable. In VB that is not the case, so you cannot perform an assignment and compare the assigned value in one line. In VB you'd have to do something like this:
VB Code:
packet = device.PcapGetNextPacket()
While packet IsNot Nothing
'Do something.
packet = device.PcapGetNextPacket()
End While
Note that IsNot is new in VB 2005. ALWAYS specify your version. In previous versions you have to use Not ... Is.