Problem adding to output file

I must be doing something really stupid or I’m totally blind today but I am having trouble appending to an RTF file.

Essentially, I have an offscreen textarea that I am sending data to and giving it style information before writing it to an RTF file. The problem I have is that only the first set of data gets written to the file. Here’s the code (‘file’ is the folderitem that has already been successfully created):

[code]s = TextOutputStream.Create(file)

taOffScreen.text = “The Title”
taOffScreen.TextFont = “Calibri”
taOffScreen.TextSize = 36
taOffScreen.Underline = True
s.Write (taOffScreen.StyledText.RTFData)
s.WriteLine

taOffScreen.text = “The information”
s.Write (taOffScreen.StyledText.RTFData)
s.WriteLine

s.Close
[/code]

After running this, looking at the resulting file shows only the first line. If I comment out the first section, after the creation of the TextOutputStream, the second part gets sent to the file correctly so I know the text is being sent to the offscreen textarea. If I look at it in the debugger, I do see the correct text in the textarea at the right time.

Is there some reason I can only write to the RTF file once? Am I missing something?

  • Dale

TextOutputStream.Create
That overwrites the file every time
http://documentation.xojo.com/index.php/TextOutputStream
Try using append instead

taOffScreen.text = “The information” - replaces “The Title” with “The information”

maybe better use taOffScreen.AppendText ?

Here is the RTF code you get with your method :

{\\rtf1\\ansi\\ansicpg1252{\\fonttbl{\\f0\\fnil Calibri;}}{\\colortbl\\red0\\green0\\blue0;}\\uc0 \\ql\\ul\\f0\\fs72 The title} {\\rtf1\\ansi\\ansicpg1252{\\fonttbl{\\f0\\fnil Calibri;}}{\\colortbl\\red0\\green0\\blue0;}\\uc0 \\ql\\ul\\f0\\fs72 The information}

If you look at it, it contains twice the header {\\rtf1 and immediately after the text a closing brace } which means end of document. So in practice the RTF contains two documents, and as a result you see only one, because the interpreter encountered the closing brace and stopped loading data.

The proper way is to concatenate in taOffScreen, then write the RTFData from that :

[code] taOffScreen.Text = “The title”+EndOfLine+“The Information” // Or use .AppendText
TextArea2.AppendText(taOffScreen.StyledText.RTFData)

s.Write (taOffScreen.StyledText.RTFData)
s.WriteLine

s.Close[/code]

{\\rtf1\\ansi\\ansicpg1252{\\fonttbl{\\f0\\fnil Calibri;}}{\\colortbl\\red0\\green0\\blue0;}\\uc0 \\ql\\ul\\f0\\fs72 The title\\par The Information}

Ahhh. Now that I see the RTF code it all makes sense. Thanks Michel.

-Dale