Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

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!




Newlines

 
Reply to this topicStart new topic

Newlines, vbcrlf does not work in multiline text box! HALP!

obrzut
post 3 Oct, 2008 - 07:57 PM
Post #1


New D.I.C Head

*
Joined: 3 Oct, 2008
Posts: 10

CODE

            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

So, what the hail mary do I do?!

Please help!
User is offlineProfile CardPM

Go to the top of the page


akhileshbc
post 3 Oct, 2008 - 08:00 PM
Post #2


D.I.C Head

Group Icon
Joined: 26 Sep, 2008
Posts: 177



Thanked 3 times

Dream Kudos: 50
My Contributions


Is this vb6 or .net...???
If vb6, try this:

txtTCPmsg.Text=txtTCPmsg.Text & returndata & vbCrLf
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 3 Oct, 2008 - 08:09 PM
Post #3


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,906



Thanked 116 times

Dream Kudos: 8450

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Moved to VB.NET smile.gif
User is offlineProfile CardPM

Go to the top of the page

obrzut
post 3 Oct, 2008 - 08:15 PM
Post #4


New D.I.C Head

*
Joined: 3 Oct, 2008
Posts: 10

QUOTE(akhileshbc @ 3 Oct, 2008 - 09:00 PM) *

Is this vb6 or .net...???
If vb6, try this:

txtTCPmsg.Text=txtTCPmsg.Text & returndata & vbCrLf


This is vb.net 2005. Apologies - I should have made that clear in the begining.

CODE

txtTCPmsg.Text=txtTCPmsg.Text & returndata & vbCrLf



I tried this suggestion - fail.
User is offlineProfile CardPM

Go to the top of the page

obrzut
post 3 Oct, 2008 - 08:24 PM
Post #5


New D.I.C Head

*
Joined: 3 Oct, 2008
Posts: 10

QUOTE(obrzut @ 3 Oct, 2008 - 09:15 PM) *

QUOTE(akhileshbc @ 3 Oct, 2008 - 09:00 PM) *

Is this vb6 or .net...???
If vb6, try this:

txtTCPmsg.Text=txtTCPmsg.Text & returndata & vbCrLf


This is vb.net 2005. Apologies - I should have made that clear in the begining.

CODE

txtTCPmsg.Text=txtTCPmsg.Text & returndata & vbCrLf



I tried this suggestion - fail.



CODE

            ' 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!
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 3 Oct, 2008 - 09:27 PM
Post #6


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,906



Thanked 116 times

Dream Kudos: 8450

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Try using Environment.NewLine and see if that changes your luck (especially since vbCrLf is a legacy property left over from the VB6 days)

vb

txtTCPmsg.AppendText(returndata & Environment.NewLine)
User is offlineProfile CardPM

Go to the top of the page

obrzut
post 3 Oct, 2008 - 10:04 PM
Post #7


New D.I.C Head

*
Joined: 3 Oct, 2008
Posts: 10

QUOTE(PsychoCoder @ 3 Oct, 2008 - 10:27 PM) *

Try using Environment.NewLine and see if that changes your luck (especially since vbCrLf is a legacy property left over from the VB6 days)

vb

txtTCPmsg.AppendText(returndata & Environment.NewLine)



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
User is offlineProfile CardPM

Go to the top of the page

obrzut
post 3 Oct, 2008 - 10:09 PM
Post #8


New D.I.C Head

*
Joined: 3 Oct, 2008
Posts: 10

-------------------------------------------------------
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
User is offlineProfile CardPM

Go to the top of the page

AdamR
post 5 Oct, 2008 - 10:59 AM
Post #9


D.I.C Head

**
Joined: 23 Sep, 2008
Posts: 91



Thanked 1 times
My Contributions


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?
User is offlineProfile CardPM

Go to the top of the page

dbasnett
post 6 Oct, 2008 - 03:53 PM
Post #10


D.I.C Head

**
Joined: 1 Oct, 2008
Posts: 130



Thanked 5 times
My Contributions


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.
User is online!Profile CardPM

Go to the top of the page

obrzut
post 11 Oct, 2008 - 07:31 AM
Post #11


New D.I.C Head

*
Joined: 3 Oct, 2008
Posts: 10

QUOTE(AdamR @ 5 Oct, 2008 - 11:59 AM) *

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!
User is offlineProfile CardPM

Go to the top of the page

dbasnett
post 12 Oct, 2008 - 05:09 AM
Post #12


D.I.C Head

**
Joined: 1 Oct, 2008
Posts: 130



Thanked 5 times
My Contributions


CODE
        Dim buffer() As Byte = New Byte() {10, 20, 30, 40, 50, 64, 65, 127, 128, 150, 254, 255}
        TextBox1.AppendText(System.Text.Encoding.GetEncoding("utf-8").GetChars(buffer) & Environment.NewLine & "*")


the * appears on a newline in the textbox.
User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 03:29AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month