2013/11/24 Andrew Douglas Pitonyak <and...@pitonyak.org> > On 11/22/2013 06:41 PM, Johnny Rosenberg wrote: > >> Dim iNumber As Integer >> iNumber = Freefile >> Open sFilePath For Output As #iNumber >> Print #iNumber, "Line 1" >> Print #iNumber, "Line 2" >> Close #iNumber >> >> >> The file now looks like this (in hex values): >> 4C 69 6E 65 20 31 0A >> 4C 69 6E 65 20 32 0A >> >> So every line ends with 0A (Chr(10)). >> The file is going to be in a special text file format suited for a >> specific >> app, so I need every line to end with 0D 0A (Chr(13) & Chr(10)). Is that >> possible? How? Can I see a short example of that, that creates a text file >> that looks like the following? >> 4C 69 6E 65 20 31 0D 0A >> 4C 69 6E 65 20 32 0D 0A >> >> >> >> Regards >> >> Johnny Rosenberg >> >> Sadly, the obvious solution fails horribly by stripping the 0x0D > > Print #iNumber, "Line 1" & CHR$(13) > > > This solution, however, works just fine! > > Dim sFilePath$ : sFilePath = "/home/MrRosenberg/x.txt" > Dim oSFA ' SimpleFileAccess service. > Dim sFileName$ ' Name of file to open. > Dim oStream ' Stream returned from SimpleFileAccess. > Dim oTextStream ' TextStream service. > Dim sStrings ' Strings to test write / read. > Dim sInput$ ' The string that is read. > Dim s$ ' Accumulate result to print. > Dim i% ' Index variable. > > sStrings = Array("One", "UTF:Āā", "1@3") > > ' File to use. > sFileName = sFilePath > ' Create the SimpleFileAccess service. > oSFA = CreateUnoService("com.sun.star.ucb.SimpleFileAccess") > 'Create the Specialized stream. > oTextStream = CreateUnoService("com.sun.star.io.TextOutputStream") > > 'If the file already exists, delete it. > If oSFA.exists(sFileName) Then > oSFA.kill(sFileName) > End If > > ' Open the file for writing. > oStream = oSFA.openFileWrite(sFileName) > > ' Attach the simple stream to the text stream. > ' The text stream will use the simple stream. > oTextStream.setOutputStream(oStream) > > ' Write the strings. > oTextStream.writeString("Line 1" & CHR$(13) & CHR$(10)) > oTextStream.writeString("Line 2" & CHR$(13) & CHR$(10)) > > ' Close the stream. > oTextStream.closeOutput() > > -- > Andrew Pitonyak > My Macro Document: http://www.pitonyak.org/AndrewMacro.odt > Info: http://www.pitonyak.org/oo.php > > That was the kind of solution I was looking for, actually… Since it turned out that I didn't need the Windows style newline after all (I tested with the Unix style newline instead and it worked fine), I don't need this code, but SimpleFileAccess and TextOutputStream seems interesting!
Thanks! Johnny Rosenberg > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@openoffice.apache.org > For additional commands, e-mail: users-h...@openoffice.apache.org > >