Join 131,582 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,958 people online right now. Registration is fast and FREE... Join Now!
Dim bytes(tcpClient.ReceiveBufferSize) As Byte networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize)) ' Output the data received from the host to the console. Dim returndata As String = Encoding.UTF8.GetString(bytes) txtTCPmsg.AppendText(returndata & vbCrLf)
This is a code snippet from my TCP Client. Basically, I have tried EVERYTHING to get the newline to work in the multiline text box only to fail with this.
If I try any NORMAL string with txtTCPmsg.AppendText("test" & vbcrnlf) then it works like this...but only 'returndata' fails the vbCrLf
' Read the NetworkStream into a byte buffer. Dim bytes(tcpClient.ReceiveBufferSize) As Byte networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize)) ' Output the data received from the host to the console. Dim returndata As String = Encoding.UTF8.GetString(bytes) txtTCPmsg.AppendText(returndata) txtTCPmsg.AppendText(vbCrLf)
This is ONE solution. Instead of using & to append a vbCrLf to the end of the returndata string, I simply made two .AppendString calls. This WORKS! YAY!
Nope - did not work. I have also tried controlchar.newline and that did not work either. I personally think it has something to do with the .getstring() method encoding the bytes received from networkstream into a different format than the vbcrlf.
Because remember, if I change the returndata variable to "test" & vbCrLf then it works.
Up to now - my way is the only solution - to seperate the vbCrLf from the returndata string in two .AppendText methods.
This post has been edited by obrzut: 3 Oct, 2008 - 10:05 PM
------------------------------------------------------- Another solution I thought of during my time laying in bed was that I could always append the vbcrlf to the server side of the string before transmission that way it will be decoded along with the rest of the string data in the same format but I dunno if that would work? Since I have accepted my first solution I have not tried that way.
I have just tested this above method and yes it does work. If I send a vbCrLf along with the rest of the string from the TCP server it gets formatted perfectly in the txtTCPmsg text box.
This confirms that it is something to do with encoding.ascii.getstring(bytes) method not being compatible with & vbCrLf
This post has been edited by obrzut: 3 Oct, 2008 - 10:14 PM
just for the heck of it try changing the encoding to ascii. i know you may want some of the other chars, but maybe it is a combo of the encoding and newline.
I realise a solution has been found, and just to knock this up, i am just after some info.
Reading through, i would have suggested the use of:
CODE
dim wrap as string wrap = chr(10) & chr(13)
then just called
CODE
# txtTCPmsg.AppendText(returndata & Wrap)
Would this just do the same as the other, or is this some sort of very basic way that would not work?
Well, thanks for the help - but it did not work! I tried many ways of encoding the CrLf and none worked. I eventually settled on sending the vbCrLf over the network for parsing into the text box on receipt.
QUOTE(dbasnett @ 6 Oct, 2008 - 04:53 PM)
just for the heck of it try changing the encoding to ascii. i know you may want some of the other chars, but maybe it is a combo of the encoding and newline.
Oh, I did try to change the encoding to ASCII and UTF8 and others - none of that helped the situation! As I say to the other guy, the only solution I could find is to either seperate using client data and vbCRLF and not keeping them together with an & or + or send the vbCrLf over the network - which I opted to do!