Link to home
Start Free TrialLog in
Avatar of jackjohnson44
jackjohnson44

asked on

rich textbox control vb looping to bold

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?
Avatar of justchat_1
justchat_1

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
lastx=x
--all the code from above--
loop
Avatar of jackjohnson44

ASKER

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
                Else
                    breakWhile = True
                End If
            Wend
RichTextBox1.TextRTF = Replace(RichTextBox1.TextRTF, "<b>", "")
RichTextBox1.TextRTF = Replace(RichTextBox1.TextRTF, "</b>", "")
ASKER CERTIFIED SOLUTION
Avatar of justchat_1
justchat_1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial