Problem porting C# code to VB

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

    #1

    Problem porting C# code 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
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Try vbLf or vbCrLf. Or you could compare the ASCII codes. 10 is LF and 13 is CR.

    Comment

    Working...