Solved

Length of a Richtext printed string

Posted on 2004-04-26
5
635 Views
Last Modified: 2009-07-29
I need to determine the length of a Richtext string, but I only want to count the characters that actually print.  

Using the Len() function, I can determine the length of a Richtext string, but the calculation includes a long list of non-printing Richtext formatting characters (e.g. "{\rtf1\ansi\ansicpg-1\...").  Generally there appears to be 115 non-printing characters, but I've also seen 126.  I assume this is a dynamic value based on the type and amount of formatting that the user applies to the text.

Is there a way to avoid counting the formatting characters when calculating the string length?

Thanks, T.C.
0
Comment
Question by:TSClark251
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:leechoonhwee
ID: 10926729
Well if the formatting is forseeable, then probably you can apply some filter before counting the len.eg

presume strtext = "{\rtf1\ansi\ansicpg-1\xxx}"

assuming xxx is the len you want to count then wat you can do is

For i = 1 to len(strtext)
strTemp = right(strtext,i)
if strtemp = "\" then
Strlength = len(strTemp)
exit for
end if
next

You can alter the filter to the pattern that you need. Hope it explains.





0
 
LVL 7

Accepted Solution

by:
OHDev2004 earned 250 total points
ID: 10927162
doesn't Len(Richtextbox1.text) do the trick ??
because there are two options for the text
Richtextbox1.Text 'to get the plaintext
Richtextbox1.TextRtf 'to get the RtfText
OHDev2004
0
 

Author Comment

by:TSClark251
ID: 10937002
OHDev2004,

Thanks...your suggestion helped me solve the problem.  

Respectfully,
T.C.
0
 

Author Comment

by:TSClark251
ID: 10937009
leechoonhwee,

Thanks for the input.

T.C.
0
 
LVL 7

Expert Comment

by:OHDev2004
ID: 10938163
your welcome :)
OHDev2004
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

773 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