Problem porting C# to VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Johnson
    New Member
    • Oct 2010
    • 97

    Problem porting C# to VB

    Hi,

    I have a bit of code which is causing me a few problems to port from C# to VB.NET

    The C# looks like this

    Code:
        		byte[] serverbuff = new Byte[1024];
        		int count = 0;
        		while (true)
        		{
            		byte[] buff = new Byte[2];
            		int bytes = stream.Read(buff, 0, 1 );
            		if (bytes == 1)
            		{
                		serverbuff[count] = buff[0];
                		count++;
    
                		if (buff[0] == '\n')
                		{
                    		break;
                		}
            		}
            		else
            		{
               			break;
            		};
        		};
    I've ported it, but the final if is causing a problem as I can't use ControlChars.Lf - the new code looks like this

    Code:
                Dim serverbuff As Byte() = New [Byte](1023) {}
                Dim count As Integer = 0
                While (True)
                    Dim buff As Byte() = New [Byte](1) {}
                    Dim bytes As Integer = stream.Read(buff, 0, 1)
                    If (bytes = 1) Then
                        serverbuff(count) = buff(0)
                        count += 1
    'The line below fails
                        If (buff(0) = ControlChars.Lf) Then
                            Exit While
                        End If
                    Else
                        Exit While
                    End If
    
                End While
    Any idea on how to go about fixing this? It's the only part that fails

    Paul
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    you are attempting to compare a Byte with a Char, try converting the Byte to a Char, e.g.
    Code:
           If (Chr(buff(0)) = ControlChars.Lf) Then

    Comment

    Working...