Convert from C#
-
I have a function that I need to convert from C# to VB. C# public byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream) { int b1; System.IO.MemoryStream tempStream = new System.IO.MemoryStream(); while((b1=theStream.ReadByte())!=-1) { tempStream.WriteByte(((byte)b1)); } return tempStream.ToArray(); } My VB So far... Public Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte() Dim b1 As Integer Dim tempStream As New System.IO.MemoryStream While ((b1 = theStream.ReadByte()) <> -1) tempStream.WriteByte(((byte)b1)) End While Return tempStream.ToArray() End Function i keep getting an error of: 'Byte' is a type, and so is not a valid expression. referring to the code in the while statement. Please can someone help me to convert the function Thank You
-
I have a function that I need to convert from C# to VB. C# public byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream) { int b1; System.IO.MemoryStream tempStream = new System.IO.MemoryStream(); while((b1=theStream.ReadByte())!=-1) { tempStream.WriteByte(((byte)b1)); } return tempStream.ToArray(); } My VB So far... Public Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte() Dim b1 As Integer Dim tempStream As New System.IO.MemoryStream While ((b1 = theStream.ReadByte()) <> -1) tempStream.WriteByte(((byte)b1)) End While Return tempStream.ToArray() End Function i keep getting an error of: 'Byte' is a type, and so is not a valid expression. referring to the code in the while statement. Please can someone help me to convert the function Thank You
You have only one error in the line
tempStream.WriteByte(((byte)b1))
. The VB equivelent of(byte)b1
isCType(b1, Byte)
. The full VB code should bePublic Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte()
Dim b1 As Integer
Dim tempStream As New System.IO.MemoryStream
While Not ((b1 = theStream.ReadByte) = -1)
tempStream.WriteByte(CType(b1, Byte))
End While
Return tempStream.ToArray
End Function -
You have only one error in the line
tempStream.WriteByte(((byte)b1))
. The VB equivelent of(byte)b1
isCType(b1, Byte)
. The full VB code should bePublic Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte()
Dim b1 As Integer
Dim tempStream As New System.IO.MemoryStream
While Not ((b1 = theStream.ReadByte) = -1)
tempStream.WriteByte(CType(b1, Byte))
End While
Return tempStream.ToArray
End Functionhere is a pretty cool site that converts vb to c# and vica versa - its not perfect it sure beats typing everything out - http://www.developerfusion.com/utilities/convertvbtocsharp.aspx
-
here is a pretty cool site that converts vb to c# and vica versa - its not perfect it sure beats typing everything out - http://www.developerfusion.com/utilities/convertvbtocsharp.aspx
Personaly I use SharpDevelop[^] which has a built in C# to VB.Net and VB.Net to c# converter. I use it a lot as I write in VB.Net as work and C# at home. It is quicker to convert whole classes than to rewrite from scratch, even though the conversion is only 99% perfect.
-
You have only one error in the line
tempStream.WriteByte(((byte)b1))
. The VB equivelent of(byte)b1
isCType(b1, Byte)
. The full VB code should bePublic Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte()
Dim b1 As Integer
Dim tempStream As New System.IO.MemoryStream
While Not ((b1 = theStream.ReadByte) = -1)
tempStream.WriteByte(CType(b1, Byte))
End While
Return tempStream.ToArray
End FunctionNote that this function is not very efficient. Why is
b1
an integer to begin with? And as for reading a single byte at a time...