Click here to Skip to main content
15,916,288 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello guys

I want to ask how to split lines in Richtextbox.
I have a program that work as a client. The server sent client data

ex:

Ship Speed : 40 KM/H

Direction : North - West

etc

the data is sent to client and displayed on Richtexbox at Client Form.

What i want to do right now is to split lines to textboxes

ex

Text box 1 show 40 KM/H

Text box 2 show North - West

etc

Can anyone help me? (sorry for bad grammar)
Hope my question is not confusing.

Thank you

Edit:

This is my code i tried:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim tbarry() As String = RichTextBox1.Lines.Clone

        TextBox1.Text = tbarry(0)
        TextBox2.Text = tbarry(1)
        TextBox3.Text = tbarry(2)


it works when i try it in new project. But it crash when i tried to implement it to my main program

VB
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Listener.Pending = True Then
            Message = ""
            Client = Listener.AcceptTcpClient()

            Dim Reader As New StreamReader(Client.GetStream())
            Dim tbarry() As String = RichTextBox1.Lines.Clone
            While Reader.Peek > -1
                Message = Message + Convert.ToChar(Reader.Read()).ToString
            End While
            RichTextBox1.ForeColor = Color.Black
            RichTextBox1.Text += Message + vbCrLf
            RichTextBox1.Text = RichTextBox1.Text.Replace(RichTextBox1.Text, Message + vbCrLf)
            RichTextBox2.ForeColor = Color.Black
            RichTextBox2.Text += Message + vbCrLf
            RichTextBox2.Text = RichTextBox2.Text.Replace(RichTextBox2.Text, Message + vbCrLf)



            TextBox1.Text = tbarry(0)
            TextBox2.Text = tbarry(1)
            TextBox3.Text = tbarry(2)
            
        End If

    End Sub


it said "Index was outside the bounds of the array"
Posted
Updated 31-Jul-13 19:38pm
v4
Comments
Sergey Alexandrovich Kryukov 31-Jul-13 23:44pm    
Start here: http://whathaveyoutried.com.
—SA
imunksky 1-Aug-13 0:05am    
Sorry, and thanks for telling me. I have edited the post.
Sergey Alexandrovich Kryukov 1-Aug-13 0:14am    
No problem and thank you for understanding and clarifying the question. I tried to answer.
—SA

1 solution

It simply means that the RTF text, by some reason, has less then 3 lines. Run it under the debugger and you will see. Never assume number of elements in array or some collection. Before indexing of anything which is accessed by index, always check the number of elements.

—SA
 
Share this answer
 
Comments
imunksky 1-Aug-13 1:36am    
I finally get it work. Now i just have to extract the part of the text. Thank you for the advice +5
Sergey Alexandrovich Kryukov 1-Aug-13 8:14am    
Great. You are very welcome.
Good luck, call again.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900