Results 1 to 3 of 3

Thread: Convert While in C# to VB.Net

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    6

    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

  2. #2
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    Re: Convert While in C# to VB.Net

    i think this will work

    While Not ((packet = device.PcapGetNextPacket) Is Nothing)

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. packet = device.PcapGetNextPacket()
    2.  
    3. While packet IsNot Nothing
    4.     'Do something.
    5.  
    6.     packet = device.PcapGetNextPacket()
    7. End While
    Note that IsNot is new in VB 2005. ALWAYS specify your version. In previous versions you have to use Not ... Is.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width