[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.
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
I need help with reading a RichTextBox line by line I have this code:
But can't get it to work
It just skips to the last line cryer;
Anyone know how?
Thanks!
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!

Last edited by Son_Of_Diablo on Thu Oct 13, 2011 2:27 pm, edited 1 time in total.
When setting the label text you should use this:
Code: Select all
For each line, this will append the text and write a new line string.Label14.Text += RichTextBox1.Lines(i) & vbCrLf
mandai wrote:When setting the label text you should use this:Code: Select allFor each line, this will append the text and write a new line string.Label14.Text += RichTextBox1.Lines(i) & vbCrLf
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
- A
- B
- C

Using vbLf instead of vbCrLf will fix that.
Different .Net versions will see the code differently.
Different .Net versions will see the code differently.
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 :?
It works for me. If you want it double-line spacing you can do:
Code: Select all
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?For i As Integer = 0 To RichTextBox1.Lines.Length - 1
Label4.Text += RichTextBox1.Lines(i) & vbCrLf & vbCrLf
Next
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
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

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.
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;
10 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023