Home All Groups Group Topic Archive Search About

Frustrations with RTF format.

Author
6 Apr 2006 10:01 PM
AWesner
For readability sake I’m going to first state that:
LF = Line Feed CHR(10)
CR = Carriage Return CHR(13)

Since Rich Text Format is a standard formalized by Microsoft Corporation I
get to ask them why they decided that RTF format needed to start writing LF
instead of the CRLF that you see in implemented in non formatted text such as
seen via notepad. Nor can I find any history on why the decision was made.
Was it forgotten and just left behind because RTF knew the formatting and
that was all that mattered? I only find on Google many different people in
many different coding languages trying to deal with the differences. Even on
Microsoft’s site that is all I find.

My main point of interest here is why a Richtextbox.text property would
yield a string that doesn’t fit the plain text standard which ends with CRLF?
And even if this .text property did not provide a way to do that why can't I
find an inherent method that will do this type of conversion? It’s not a
string conversion after all. They are both clearly strings but with a
different choice of line feed. Do I have to write a conversion algorithm
myself? If so, that’s fine. But from all my Google searching I know that I’m
not the first to address this issue.

Why would I want to use an old standard? Well, without a CR your plain text
files look pretty ugly and depending on which programs are trying to read
from these files, they may become dysfunctional after being written from a
Richtextbox if they are expecting CRs. I simply do not want to change the
original format of the files that go through my program and I think that’s a
reasonable request 

Using RTF is unavoidable. I need its formatting capabilities to present to
the user the plain text files with highlighted areas of importance. However
when I stuff the contents back into a plain text file, I would like the
formatting to be converted back to plain text and what I mean by that is the
implementation of CRLF instead of just LF.

I am aware of the Richtextbox.Savefile method. However this cannot be used
to set the value to another data structure within memory and has to use the
FSO to store and retrieve the data. This is undesirable for the solution I
need. But this is the only way I currently know of that will do the proper
type of conversion for you.

If somebody can tell me an easy way to accomplish this in VB.net

1: Create a form.
2: Place 1 Pushbutton, 1 Richtextbox and 1 Textbox.
3: Change the properties of the textbox to Multiline = True and WordWrap =
False.
4: Make the boxes big enough to show a few lines of text.

Enter the code for the Click event of Pushbutton: Textbox.text =
Richtextbox.text

Now go run the program and enter in a few lines of data into the RTB and hit
the pushbutton. Watch as the textbox fails to write new lines properly
because there is no CR.

How do I efficiently get around this without reinventing the wheel?

Author
6 Apr 2006 11:05 PM
Ray Cassick (Home)
I am not sure what you are trying to accomplish here. If you want to use an
RTF control to get all your formatting and stuff then why are you trying to
display that text in a plain text box and expect it to look anything like
the RTF formatted document. Open a MS Word doc in Notepad and see what you
get. If you want to get the data out of Word into a plain text file you need
to do a Save As and select a different file type that invariably takes a
different code path and saves the text as raw ASCII. Doing this even brings
up a dialog box that allows you to pick the formatting that you want to use
for that plain text document. It lets you sent the encoding to use, the
ability to insert line breaks, to end lines with CR\LF - LF\CR - CR Only -
LF Only, and even to do character substitution.

I would suggest that things are not as 'standard' as you had hoped but there
is no doubt that RTF in and of itself is a standard and so is ASCII text.
You can't compare the two as apples-to-apples and clearly converting between
them is going to take some wheel inventing to get done what you want.


Show quoteHide quote
"AWesner" <AWes***@discussions.microsoft.com> wrote in message
news:AA995236-9766-459E-9FC5-B7FF9CAC2B01@microsoft.com...
> For readability sake I'm going to first state that:
> LF = Line Feed CHR(10)
> CR = Carriage Return CHR(13)
>
> Since Rich Text Format is a standard formalized by Microsoft Corporation I
> get to ask them why they decided that RTF format needed to start writing
> LF
> instead of the CRLF that you see in implemented in non formatted text such
> as
> seen via notepad. Nor can I find any history on why the decision was made.
> Was it forgotten and just left behind because RTF knew the formatting and
> that was all that mattered? I only find on Google many different people in
> many different coding languages trying to deal with the differences. Even
> on
> Microsoft's site that is all I find.
>
> My main point of interest here is why a Richtextbox.text property would
> yield a string that doesn't fit the plain text standard which ends with
> CRLF?
> And even if this .text property did not provide a way to do that why can't
> I
> find an inherent method that will do this type of conversion? It's not a
> string conversion after all. They are both clearly strings but with a
> different choice of line feed. Do I have to write a conversion algorithm
> myself? If so, that's fine. But from all my Google searching I know that I'm
> not the first to address this issue.
>
> Why would I want to use an old standard? Well, without a CR your plain
> text
> files look pretty ugly and depending on which programs are trying to read
> from these files, they may become dysfunctional after being written from a
> Richtextbox if they are expecting CRs. I simply do not want to change the
> original format of the files that go through my program and I think that's
> a
> reasonable request ?
>
> Using RTF is unavoidable. I need its formatting capabilities to present to
> the user the plain text files with highlighted areas of importance.
> However
> when I stuff the contents back into a plain text file, I would like the
> formatting to be converted back to plain text and what I mean by that is
> the
> implementation of CRLF instead of just LF.
>
> I am aware of the Richtextbox.Savefile method. However this cannot be used
> to set the value to another data structure within memory and has to use
> the
> FSO to store and retrieve the data. This is undesirable for the solution I
> need. But this is the only way I currently know of that will do the proper
> type of conversion for you.
>
> If somebody can tell me an easy way to accomplish this in VB.net
>
> 1: Create a form.
> 2: Place 1 Pushbutton, 1 Richtextbox and 1 Textbox.
> 3: Change the properties of the textbox to Multiline = True and WordWrap =
> False.
> 4: Make the boxes big enough to show a few lines of text.
>
> Enter the code for the Click event of Pushbutton: Textbox.text =
> Richtextbox.text
>
> Now go run the program and enter in a few lines of data into the RTB and
> hit
> the pushbutton. Watch as the textbox fails to write new lines properly
> because there is no CR.
>
> How do I efficiently get around this without reinventing the wheel?
>
Author
7 Apr 2006 12:11 AM
AWesner
Thank you for your response.

"I am not sure what you are trying to accomplish here. If you want to use an
RTF control to get all your formatting and stuff then why are you trying to
display that text in a plain text box and expect it to look anything like
the RTF formatted document. Open a MS Word doc in Notepad and see what you
get."

My example of loading text from an RTF to text is the opposite of what you
are expecting here. My goal is to use the RTF to highlight text but I wanted
it to lose all formatting when it reached the text box. And so far, except
the CR this is true.

I admit that using a Richtextbox for what I am trying to accomplish may not
be the correct solution. But at the moment I am uneducated as to what would
be better to display multiple highlighted text.

What I am trying to do is load many, possibly hundreds, of text files into
an array for search and replace purposes. The search procedure runs through
these files finding and highlighting search strings so that it is easier on
the user to see where the subject string(s) is/are located. Each file that is
changed whether manually or programatically is marked as being changed so
that it can be saved at a later time.

"If you want to get the data out of Word into a plain text file you need
to do a Save As and select a different file type that invariably takes a
different code path and saves the text as raw ASCII. Doing this even brings
up a dialog box that allows you to pick the formatting that you want to use
for that plain text document. It lets you sent the encoding to use, the
ability to insert line breaks, to end lines with CR\LF - LF\CR - CR Only -
LF Only, and even to do character substitution."

Both of the facts that each file already has its path set and that there are
hundreds of these waiting to be saved has detered me from bugging the user
with a savedialog. I have looked into the savedialog help file to see if I
could catch a glimpse of some code example showing plain text files being
saved but I never did. My best efforts so far were to use the FSO in various
methods to try to write in ANY format available to see if it changed the text
file result, including ASCII. It didnt. But as you point out I was not using
the Savedialog formats. I will give this further investigation since you
brought it up and see if I can't skip the dialog popup but use it's format.

Thanks
Author
7 Apr 2006 1:33 AM
ShaneO
AWesner wrote:
Show quoteHide quote
>
> If somebody can tell me an easy way to accomplish this in VB.net
>
> 1: Create a form.
> 2: Place 1 Pushbutton, 1 Richtextbox and 1 Textbox.
> 3: Change the properties of the textbox to Multiline = True and WordWrap =
> False.
> 4: Make the boxes big enough to show a few lines of text.
>
> Enter the code for the Click event of Pushbutton: Textbox.text =
> Richtextbox.text
>
> Now go run the program and enter in a few lines of data into the RTB and hit
> the pushbutton. Watch as the textbox fails to write new lines properly
> because there is no CR.
>
> How do I efficiently get around this without reinventing the wheel?
>

Do the following in your Button Click Event -

TextBox1.Text = RichTextBox1.Text.Replace(ChrW(10), vbCrLf)

Regards,

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Author
7 Apr 2006 3:41 PM
AWesner
Simple and effective. For my purposes this works very well.

Thanks



Show quoteHide quote
"ShaneO" wrote:

> AWesner wrote:
> >
> > If somebody can tell me an easy way to accomplish this in VB.net
> >
> > 1: Create a form.
> > 2: Place 1 Pushbutton, 1 Richtextbox and 1 Textbox.
> > 3: Change the properties of the textbox to Multiline = True and WordWrap =
> > False.
> > 4: Make the boxes big enough to show a few lines of text.
> >
> > Enter the code for the Click event of Pushbutton: Textbox.text =
> > Richtextbox.text
> >
> > Now go run the program and enter in a few lines of data into the RTB and hit
> > the pushbutton. Watch as the textbox fails to write new lines properly
> > because there is no CR.
> >
> > How do I efficiently get around this without reinventing the wheel?
> >
>
> Do the following in your Button Click Event -
>
> TextBox1.Text = RichTextBox1.Text.Replace(ChrW(10), vbCrLf)
>
> Regards,
>
> ShaneO
>
> There are 10 kinds of people - Those who understand Binary and those who
> don't.
>