Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Length of a Richtext printed string

Posted on 2004-04-26
5
Medium Priority
?
643 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

971 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