Page 1 of 1
[SOLVED] [HELP] Read RichTextBox line by line
Posted: Wed Oct 12, 2011 11:26 am
by Son_Of_Diablo
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!

Re: [HELP] Read RichTextBox line by line
Posted: Wed Oct 12, 2011 11:43 am
by mandai
When setting the label text you should use this:
Code: Select allLabel14.Text += RichTextBox1.Lines(i) & vbCrLf
For each line, this will append the text and write a new line string.
Re: [HELP] Read RichTextBox line by line
Posted: Wed Oct 12, 2011 11:49 am
by Son_Of_Diablo
mandai wrote:When setting the label text you should use this:
Code: Select allLabel14.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:
Then the label shows:
...
...

Re: [HELP] Read RichTextBox line by line
Posted: Wed Oct 12, 2011 11:54 am
by mandai
Using vbLf instead of vbCrLf will fix that.
Different .Net versions will see the code differently.
Re: [HELP] Read RichTextBox line by line
Posted: Wed Oct 12, 2011 11:58 am
by Son_Of_Diablo
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 :?
Re: [HELP] Read RichTextBox line by line
Posted: Wed Oct 12, 2011 11:49 pm
by mandai
Can anyone else confirm this?
Re: [HELP] Read RichTextBox line by line
Posted: Thu Oct 13, 2011 3:19 am
by CodenStuff
It works for me. If you want it double-line spacing you can do:
Code: Select allFor 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?
Re: [HELP] Read RichTextBox line by line
Posted: Thu Oct 13, 2011 6:05 am
by Son_Of_Diablo
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!
I want to show 1 line at a time and then it cleans the line and show another one

Re: [HELP] Read RichTextBox line by line
Posted: Thu Oct 13, 2011 8:10 am
by CodenStuff
You can do that by using a Timer and something like this:
Code: Select allPublic 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
Re: [HELP] Read RichTextBox line by line
Posted: Thu Oct 13, 2011 11:34 am
by Son_Of_Diablo
CodenStuff wrote:You can do that by using a Timer and something like this:
Code: Select allPublic 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!

It worked!
wahooo; wahooo; wahooo; wahooo; wahooo; wahooo; wahooo; wahooo;