How to set selected text bold

pasensyoso_manigbas

Well-known member
Joined
May 19, 2006
Messages
64
Programming Experience
Beginner
Good day mods!

Excuse me, for the title, I just couldn't find the right words to say it but, the thing is, I just want to make a certain word inside a paragraph bold. The word will be automatically set to bold in runtime. See for example the words 'John' shall be all set to bold.

Here is the code:

tempstr = tempstr.Replace(vbTab, "")
Dim secstr As String = tempstr.Replace(Chr(10), " ")
str = Split(secstr, " ")

for each x in str
select case x
case Is ="John"
txtpara.SelectionStart = txtpara.Find(x)
txtpara.SelectionFont = boldfont
end select
next

the output of the above code is, it only makes the first occurence bold. All other word "John" are just set to Regular text when what I want is to make it all bold.

What is lacking? I used the "for each loop" to visit all the words.
Any help?
 

demausdauth

Well-known member
Joined
Mar 24, 2008
Messages
281
Location
Minnesota
Programming Experience
3-5
Your ForEach loop is searching through your list of words to find, not the text.
The RichTextBox.Find() method will only find the first instance of the word, you need to tell it to search again from an index after where the first instance was found.
 

pasensyoso_manigbas

Well-known member
Joined
May 19, 2006
Messages
64
Programming Experience
Beginner
Thanks demausdauth! I have figured it out. Thanks for the hint pal!

Best Regards!
 
Top Bottom