Question For and Rich Text Box

Syzis

Member
Joined
Apr 23, 2011
Messages
10
Programming Experience
3-5
Hello,

I'm having some problems getting my application to write all text I want in the rich text box .

An example is:

For i = 0 to 5
Richtextbox1.text = "Number: " & i & vbcrlf
Next i

This code only keep last number into richtextbox.

What I want is something like:
0
1
2
3
4
5

And not only
5

I need help in this case.
Thanks again :)
 
Last edited:
You can get the existing Text and add your new, then assign all that to Text again:
rtb.Text = rtb.Text & vbNewLine & "new text"

shorthand is &= operator:
rtb.Text &= vbNewLine & "new text"

You can also use the AppendText method:
rtb.AppendText(vbNewLine & "new text")

For larger content you can also build up your total string, perhaps using a StringBuilder, and at the end assign it to Text property only once, to prevent lots of unnecesary updates of the UI control.
 
Back
Top