get codepage from a rich text box control

Posted on 2005-05-17
Last Modified: 2012-06-27

How can I get and set the codepage from a rich text box

Please Help me
Question by:LPlate
    LVL 8

    Expert Comment

    If I am correct you want to see the code window relevant to the text box then simply in design view and as long as your appication is not running double click on the text box and the code window will appear.

    You can then select the events form the right hand side drop down window to perform tasks at relevant event procedures or when each event for the control occurs.


    Author Comment

    Hi HTH,

    No thats not what i mean, I have a richtextbox and i need to know what codepage is used at runtime
    LVL 13

    Accepted Solution


    You need to read the control word "ansicpg" inside the rtf code, please take a look at and then try this code:

    Private Sub SetCodePage(cpg As Long, rtb As RichTextBox)

        Dim cpgstart As Long
        Dim cpgend As Long
        cpgstart = InStr(1, rtb.TextRTF, "\ansicpg") + Len("\ansicpg") - 1
        cpgend = InStr(cpgstart, rtb.TextRTF, "\")
        rtb.TextRTF = Left(rtb.TextRTF, cpgstart) + Format(cpg) + Mid(rtb.TextRTF, cpgend)

    End Sub

    Private Function GetCodePage(rtb As RichTextBox) As Long

        Dim cpgstart As Long
        Dim cpgend As Long
        cpgstart = InStr(1, rtb.TextRTF, "\ansicpg") + Len("\ansicpg")
        cpgend = InStr(cpgstart, rtb.TextRTF, "\")
        GetCodePage = CLng(Mid(rtb.TextRTF, cpgstart, cpgend - cpgstart))

    End Function

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    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…

    779 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

    9 Experts available now in Live!

    Get 1:1 Help Now