Determine Bold,Underline and Italic Characters in rich text box control

Posted on 2005-05-09
Last Modified: 2013-12-03

I'm currently doing a project using a rich text control in Visual Basic 6.
I need to output the data from a rich text control into a binary file, remembering what characters font styles have been used within the data (BOLD, UNDERLINE OR ITALIC).

Please help. :->

Question by:LPlate
    LVL 13

    Expert Comment


    You can save the data in a RTF file and preserve all formatting attributes

    RichTextBox1.SaveFile "C:\myfile.rtf"
    LVL 13

    Expert Comment

    To load the file again use

    RichTextBox1.LoadFile "c:\myfile.rtf"

    Author Comment

    The Device that I output to only supports Binary format files.

    For Example, if the rich text box contains the following data "Hello World I'm in hot water", and lets say all o characters are bold, the output file will look like this:

    "HellESC<b>oESC<bo> WESC<b>oESC<bo>rld I'm in hESC<b>oESC<bo>t water"

    I need to know what characters are Underline, Bold or Italic to that I can generate the data above.
    LVL 13

    Accepted Solution

    ok, if you just want to know what chars are underline, bold or italic, use .SelBold, .SelItalic and .SelUnderline properties.

    This can give you an idea:

        Dim I As Long
        Dim Result As String
        With RichTextBox1
            For I = 0 To Len(.Text)
                .SelStart = I
                .SelLength = 1
                If .SelBold Then Result = Result + "<b>"
                If .SelItalic Then Result = Result + "<i>"
                If .SelUnderline Then Result = Result + "<u>"
                Result = Result + .SelText
                If .SelUnderline Then Result = Result + "</u>"
                If .SelItalic Then Result = Result + "</i>"
                If .SelBold Then Result = Result + "</b>"
        End With
        Debug.Print Result

    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…
    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    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…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    729 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

    23 Experts available now in Live!

    Get 1:1 Help Now