VB.NET How can I add text to rich text box without replacing what's already there?

simpleonline12

New member
Sep 29, 2009
191
3
0
Not sure what I am doing wrong here but I have 2 buttons and a rich text box. The issue is when I click the second button to add text to the rich text box and it over writes the current text that is already in the rich text box. How can I code this second button so that the text is added to the rich text box and not replacing the current text?

Here's my code:

Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        RichTextBox1.Text = "This is the first line"
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        RichTextBox1.Text = "This is the second line"
    End Sub
End Class

Also how can I add spaces in a line of text (or in the middle of a sentence) so that I can insert a variable in the line.
Example: "This is the" variable1 "line of text"
"This is the" variable2 "line of text"
 


(this is all from quick googling)
for adding a string to the box, try

box.Text &= "moar text"

or box.Text = box.Text & "moar text"

for the 2nd item, it should be "blah" & variable & "blah blah"