rich textbox control vb looping to bold

Posted on 2006-06-23
Last Modified: 2010-04-30
I would like to use html tags in a rich textbox control to bold text inside <b> </b> tags.
I would like to enter the text, then have some code that will go through and find any text between the tags and bold it.

mystring="<b>bold this</b> regular font <b>bold this too</b>regular font<b>bold this three</b>"
rtxtText1.Text = mystring

how would I do this?
Question by:jackjohnson44
  • 3

Expert Comment

ID: 16970457
Use the instr method to find the <b> tags and </b> tags.  
Then set selStart as the first value and selLength as the second value minus the first value.
Calling selBold should take care of the bold issue.
Finally a replace statment for "<b>" and "<\b>" should get rid of the tags

As far as the loop:
while x<>last x
--all the code from above--

Author Comment

ID: 16970778
I got my code to work so that the part that I want bold is bold.
After this happens, how do I get rid of the bold tags?  <B> and <\B>?

            While (positionCounter <= Len(currentStepType(CStr(i)).value)) And (breakWhile = False)
                If InStr(positionCounter, currentStepType(CStr(i)).value, "<B>") > 0 Then
                    rtxtMatrixDescription.SelStart = InStr(positionCounter, currentStepType(CStr(i)).value, "<B>")
                    rtxtMatrixDescription.SelLength = InStr(rtxtMatrixDescription.SelStart, currentStepType(CStr(i)).value, "</B>") - rtxtMatrixDescription.SelStart
                    positionCounter = rtxtMatrixDescription.SelStart + rtxtMatrixDescription.SelLength
                    rtxtMatrixDescription.SelBold = True
                    breakWhile = True
                End If

Expert Comment

ID: 16971152
RichTextBox1.TextRTF = Replace(RichTextBox1.TextRTF, "<b>", "")
RichTextBox1.TextRTF = Replace(RichTextBox1.TextRTF, "</b>", "")

Accepted Solution

justchat_1 earned 500 total points
ID: 16971158
well in your case:
rtxtMatrixDescription.TextRTF = Replace(rtxtMatrixDescription.TextRTF, "<b>", "")
rtxtMatrixDescription.TextRTF = Replace(rtxtMatrixDescription.TextRTF, "</b>", "")

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now