Ask Your Question

Base macro code (in Basic) to write to a UTF-8 text file

asked 2019-12-05 01:26:09 +0200

Tromso gravatar image

Is there a reasonably simple way to modify the following example code so that the output text file is UTF-8 ?


sFName = "file:///E:/Test.utf8"


REM Ignoring newline characters, the following string is written to the file as a single character - 0xA3.

PRINT #1 "£"

REM For UTF-8, it needs to have been written to the file as two characters - 0xC2 0xA3.


edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-12-05 02:55:50 +0200

Ratslinger gravatar image
edit flag offensive delete link more


Dear @Ratslinger,

And how can we add more lines into the existing text file ?

lonk gravatar imagelonk ( 2019-12-05 10:13:33 +0200 )edit

Thanks Ratslinger. That link taught me how to successfully modify my macro.

Tromso gravatar imageTromso ( 2019-12-05 11:26:03 +0200 )edit


myTextFile.writeString(myText & chr(10))

does the actual writing of the line. Instead of calling the routine from another sub (with just the one line) you would make the sub all inclusive and place your own mechanism (such as a loop) to write all content to the file.

Ratslinger gravatar imageRatslinger ( 2019-12-05 18:00:33 +0200 )edit

Dear @Ratslinger,

Sorry for such a very short question, actually I'd like to open previously saved text file and add more lines into it. From this code, how can I do next ?

lonk gravatar imagelonk ( 2019-12-05 18:54:44 +0200 )edit


You should ask this as a new question. What you are doing here is hijacking another question and adding different conditions. This then gets buried from others to find.

You may also/instead review Open Office Macros Explained by Andrew Pitonyak. Section 8 File Routines cover much on the topic. PDF here -> OOME.

This post may also be of help -> Append text in a notepad/.txt file

Ratslinger gravatar imageRatslinger ( 2019-12-05 20:13:56 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-12-05 01:26:09 +0200

Seen: 156 times

Last updated: Dec 05 '19