Adding text to richtextbox and textbox value?

simpleonline

Active member
Joined
Sep 13, 2011
Messages
33
Programming Experience
Beginner
I have a richtextbox and I am adding text to the rich text box programmically using:

VB.NET:
RichTextBox1.AppendText(Environment.NewLine & "The red fox jumps over the"

I have a variable called "myvariable"

How can I program my button to type the text above and then insert variable's value in one line?

Example:
Let's that myvariable = "moon"

How can I code my button to say
"The red fox jumps over the moon"

Thanks
 
Last edited:
You want to update the richtextbox in one go?

You can build the string before you update it?

dim mystring as string = "hello "

Then in the button click event, you could say something like

mystring = mystring & "world" 'mystring equals its current value AND whatever else
richtextbox1.text = mystring


Or, im guessing here i havent checked it works..


RichTextBox1.Text =Environment.NewLine & "The red fox jumps over the"
RichTextBox1.AppendText(" moon")
RichTextBox1.AppendText(" heres a bit more text aswell")

Theres a few ways to do it really, i'm just putting how i think looks simplest, it might not be the best way, as said in another thread there is probably methods to use like append etc.
 
You already know how to join two Strings because you're already doing it:
VB.NET:
RichTextBox1.AppendText([COLOR="#FF0000"]Environment.NewLine[/COLOR] [B][U]&[/U][/B] [COLOR="#0000FF"]"The red fox jumps over the"[/COLOR])
You have two Strings and you're concatenating them and passing the result to AppendText. If you want to concatenate a third String then you do it the same way.
 
Back
Top