[SOLVED] [HELP] Read RichTextBox line by line

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
10 posts Page 1 of 1
Contributors
User avatar
Son_Of_Diablo
Just Registered
Just Registered
Posts: 9
Joined: Tue May 31, 2011 1:51 pm

I need help with reading a RichTextBox line by line I have this code:
Code: Select all
        For i As Integer = 0 To RichTextBox1.Lines.Length - 1
            Label14.Text = (RichTextBox1.Lines(i))
        Next


But can't get it to work
It just skips to the last line cryer;


Anyone know how?



Thanks! :D
Last edited by Son_Of_Diablo on Thu Oct 13, 2011 2:27 pm, edited 1 time in total.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

When setting the label text you should use this:
Code: Select all
Label14.Text += RichTextBox1.Lines(i) & vbCrLf
For each line, this will append the text and write a new line string.
User avatar
Son_Of_Diablo
Just Registered
Just Registered
Posts: 9
Joined: Tue May 31, 2011 1:51 pm

mandai wrote:
When setting the label text you should use this:
Code: Select all
Label14.Text += RichTextBox1.Lines(i) & vbCrLf
For each line, this will append the text and write a new line string.


Not exactly what i wanted, I want it to show the lines one by one so lets say the textbox looks like this:
  • A
    B
    C
Then the label shows:
  • A
...
  • B
...
  • C
:)
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Using vbLf instead of vbCrLf will fix that.
Different .Net versions will see the code differently.
User avatar
Son_Of_Diablo
Just Registered
Just Registered
Posts: 9
Joined: Tue May 31, 2011 1:51 pm

mandai wrote:
Using vbLf instead of vbCrLf will fix that.
Different .Net versions will see the code differently.

I get the same result when i use vbLf and vbCrLf :?
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Can anyone else confirm this?
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

It works for me. If you want it double-line spacing you can do:
Code: Select all
For i As Integer = 0 To RichTextBox1.Lines.Length - 1
            Label4.Text += RichTextBox1.Lines(i) & vbCrLf & vbCrLf
        Next
Im a little confused about what you are trying to do do you want the text from richtextbox to show in the label all at once or are you trying to do some type of rotating banner type thing where it shows 1 line at a time in the label?
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Son_Of_Diablo
Just Registered
Just Registered
Posts: 9
Joined: Tue May 31, 2011 1:51 pm

CodenStuff wrote:
Im a little confused about what you are trying to do do you want the text from richtextbox to show in the label all at once or are you trying to do some type of rotating banner type thing where it shows 1 line at a time in the label?
You got it right! :D

I want to show 1 line at a time and then it cleans the line and show another one :)
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

You can do that by using a Timer and something like this:
Code: Select all
Public RotateCount = 0
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        If RotateCount = RichTextBox1.Lines.Count Then
            RotateCount = 0
        End If
        Label4.Text = RichTextBox1.Lines(RotateCount)
        RotateCount += 1
    End Sub
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Son_Of_Diablo
Just Registered
Just Registered
Posts: 9
Joined: Tue May 31, 2011 1:51 pm

CodenStuff wrote:
You can do that by using a Timer and something like this:
Code: Select all
Public RotateCount = 0
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        If RotateCount = RichTextBox1.Lines.Count Then
            RotateCount = 0
        End If
        Label4.Text = RichTextBox1.Lines(RotateCount)
        RotateCount += 1
    End Sub


Thank you CodenStuff! :D
It worked! :D

wahooo; wahooo; wahooo; wahooo; wahooo; wahooo; wahooo; wahooo;
10 posts Page 1 of 1
Return to “Coding Help & Support”