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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best way to parse out a json string in VB6? 10 163
VBA: Select SQL query based on a config Sheet v2 11 44
Recommendation vb6 to or others 14 142
Help me. 3 54
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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