c# to vb .net (2005) help

I want to convert this c# code to vb, please help.

while (
window[++scan] == window[++match] &&
window[++scan] == window[++match] &&
window[++scan] == window[++match] &&
window[++scan] == window[++match] &&
window[++scan] == window[++match] &&
window[++scan] == window[++match] &&
window[++scan] == window[++match] &&
window[++scan] == window[++match] &&
(scan < strend))
{
// Do nothing
}

Thanks
Javfarary


Answer this question

c# to vb .net (2005) help

  • Sai A

    Now I know why I code in C#.
  • Tryin2Bgood

    The first "Exit Do" should be an "Exit For".

    But the problem is that you'll rarely have a while loop that can be easily converted to a VB 'For' loop. In general, there are many cases of "assignments within expressions" that have no direct VB equivalent (and some that have absolutely no equivalent).

    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB to C# converter
    Instant VB: C# to VB converter
    Instant C++: C# to C++ converter, VB to C++ converter
    Instant Python: VB to Python converter



  • hotsauce

    Here's a VB equivalent:

    Do
    scan = scan + 1
    match = match + 1
    If window(scan) = window (match) Then
    scan = scan + 1
    match = match + 1
    If window(scan) = window (match) Then
    scan = scan + 1
    match = match + 1
    If window(scan) = window (match) Then
    scan = scan + 1
    match = match + 1
    If window(scan) = window (match) Then
    scan = scan + 1
    match = match + 1
    If window(scan) = window (match) Then
    scan = scan + 1
    match = match + 1
    If window(scan) = window (match) Then
    scan = scan + 1
    match = match + 1
    If window(scan) = window (match) Then
    scan = scan + 1
    match = match + 1
    If window(scan) = window (match) Then
    If scan < strend Then
    ' Do Nothing
    Else
    Exit Do
    End If
    Else
    Exit Do
    End If
    Else
    Exit Do
    End If
    Else
    Exit Do
    End If
    Else
    Exit Do
    End If
    Else
    Exit Do
    End If
    Else
    Exit Do
    End If
    Else
    Exit Do
    End If
    Else
    Exit Do
    End If
    Loop

    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB to C# converter
    Instant VB: C# to VB converter
    Instant C++: C# to C++ converter, VB to C++ converter
    Instant Python: VB to Python converter



  • crbeckman

    Thanks for the help.

    Javfarary

  • chutachut

    what about the following converted code for vb I got it from other forums.
    what do you say any suggestions

    Do
    For i As Integer = 1 To 8
    scan += 1
    match += 1
    If window(scan) <> window (match) Then Exit Do
    Next
    If scan >= strend Then Exit Do
    ' Do Nothing
    Exit Do
    Loop

    Thanks
    Javfarary

  • Cefa68000

    That is pretty ugly code. It's also pretty inefficient. Is there any reason why you are comparing 8 elements at a time

    Nevertheless VB does not have a prefix increment operator so ++scan would convert to scan = scan + 1. This is a statement and not an expression so you can't do it inside the array element either. In other words the code won't translate directly. Instead you need to break down the code to a simpler format and then convert it.

    Here is a first pass (I didn't test it):

    while (scan < strend && window[scan] == window[match])
    {
    ++scan;
    ++match;
    };

    You could also use a for loop. Here is a first pass using a format that would translate to VB (there are other formats that wouldn't):

    match = 0;
    for(scan = 0; scan < strend; ++scan)
    {
    ++match;
    if (window[scan] != window[match])
    break;
    };

    The while loop would translate to (not quite sure of the VB syntax):

    While (scan < strend) AndAlso (window(scan) = window(match))
    scan = scan + 1
    match = match + 1
    End While

    The for loop would translate to:

    For scan = 0 To strend - 1
    match = match + 1
    If window(scan) <> window(match)) Then
    Break
    End If
    Next

    If all you want to do is compare two portions of an array then there is the ArraySegment class in v2 that might be better for you.

    Michael Taylor - 12/22/06


  • c# to vb .net (2005) help