get codepage from a rich text box control

Hi,

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

Please Help me
LPlateAsked:
Who is Participating?
 
rettiseertCommented:
Hi

You need to read the control word "ansicpg" inside the rtf code, please take a look at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnrtfspec/html/rtfspec_6.asp 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)
   
    rtb.Refresh

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
0
 
pjcrooks2000Commented:
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.

HTH
0
 
LPlateAuthor Commented:
Hi HTH,

No thats not what i mean, I have a richtextbox and i need to know what codepage is used at runtime
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.