Rich Text Box Controls

Inserting text

Inserting text with the rich textbox control is made very simple.  It has three parts: SelStart, SelLenth, and SelText.  The SelStart is where the text is going to be inserted (in letters), and can't be longer than the the text.  SelLength is the total number of letter that will be deleted after SelStart.  SelText is the text that is going to replace the SelLength.  If SelLength is zero the SelText will just be inserted where SelStart is.

Object.SelStart = Integer
Object.SelLenth = Integer
Object.SelText = Text

'RichTextBox1 displays "Good "
RichTextBox1.SelStart = 5
RichTextBox1.SelText = "Evening"
'RichTextBox1 now displays "Good Evening

If you want to replace text I suggest you do the Replace function.  The following is how to make a replace function.

Object = Replace(String, Find, ReplaceWith, _
Start, NumerToCorrect)

Dim Temp As String
'I prefure to use a variable
Temp = RichTextBox1.Text
'RichTextBox1 displays "aaAaAAaa"
Temp = Replace(Temp, "a", "B", 2, 3)
RichTextBox1.Text = Temp
'RichTextBox1 now displays "aBABAABa"

It replaced 3 "a" with "B" starting from the second letter of Temp and then set the text back to Temp.  That is how the replace function works.  You can skip the number of times to replace, and it will replace every existence after the start.  If you skip the start, it will start searching from the beginning.

You might also like...

Comments

About the author

ZERO-COOL United States

I'm a 12 year old child who is interested in learning programming languages. My current two are Visual Basic and C++.

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There's no test like production” - Anon