Troubleshooting
Why accented text from a UTF-8 file shows as two characters in WinCC
Short answer
OpenTextFile without a format argument cannot decode UTF-8, so é arrives as the two glyphs é. Save the source .txt as ANSI (Windows-1252 on a Western European runtime), or keep the file in UTF-8 and read it through an ADO stream with Charset set to UTF-8.

On this page
The script is not the problem and neither is the text file: the reader is decoding the file with the wrong character set. When OpenTextFile runs without its format argument, Microsoft documents that the file opens as ASCII, so the two UTF-8 bytes behind each accented letter reach the tag as two separate one-byte characters. That is why the field shows é for é, ç for ç and ù for ù. Two fixes cover every case: save the source .txt as ANSI so the one-byte decode becomes correct, or keep the file in UTF-8 and read it through an ADO stream whose Charset is set to UTF-8. The reported setup is a WinCC Runtime Advanced V17 panel under TIA Portal V17 Update 2, but the cause sits in the file reader, so both fixes hold anywhere a VBScript feeds a tag on a panel or PC runtime.
What the I/O field is actually showing #
The accented letters used in French, Spanish, German and Portuguese all encode in UTF-8 as a two-byte pair with the same lead byte, and a one-byte decoder draws that lead byte as à no matter which letter follows. Once you know that, the pattern in the field is a diagnosis, not a mystery:
| Letter in the file | UTF-8 bytes on disk | What the field shows |
|---|---|---|
| é | 0xC3 0xA9 | é |
| è | 0xC3 0xA8 | è |
| à | 0xC3 0xA0 | Ã followed by a non-breaking space |
| ç | 0xC3 0xA7 | ç |
| ù | 0xC3 0xB9 | ù |
| ô | 0xC3 0xB4 | ô |
Any byte above 127 splits the same way, so a temperature list shows ° where the editor wrote the degree sign. The recorder-side version of that fault follows the same rule: a degree sign saved as UTF-8 is two bytes, saved as ANSI it is one. The signature is not panel-specific either: declare one encoding on both sides of a text link and the split letters disappear, which is the same decision behind any CNC mojibake character encoding fix.
Why OpenTextFile cannot decode UTF-8 #
The format argument is the fourth input of OpenTextFile, it is optional, and Microsoft documents every choice it accepts. There is no UTF-8 option in the list:
TristateUseDefault(-2): open the file with the system default format.TristateTrue(-1): open the file as Unicode, which means UTF-16, not UTF-8.TristateFalse(0): open the file as ASCII.- Argument omitted: the file opens as ASCII, as the method documentation states.
None of these choices reassembles a UTF-8 pair. Do not reach for TristateTrue as a workaround: a UTF-8 file read as UTF-16 produces different garbage, because the reader pairs the bytes at the wrong offsets. The reader offers no way to declare UTF-8, so a fix has to change either the bytes or the reader.
Save the text file as ANSI #
If the runtime locale is Western European and the text stays inside Windows-1252, change the file and leave the script exactly as it stands:
- Open the .txt on the engineering station in an editor that offers an encoding choice in its Save As dialog.
- Save the file with the ANSI option, which is Windows-1252 on a Western European system.
- Deploy the file back to the location the script opens; the
pathargument does not change. - Reload the screen and run the script again:
fs.ReadLinenow returns é as a single character, andSmartTags("IOfieldString")shows it correctly.
This is the smallest possible change: no new objects, no stream handling, nothing else in the project moves. Its limit is the code page itself. One ANSI file cannot hold Western accented letters together with Greek, Cyrillic or CJK text, and that case goes to the stream read in the next section.
Read the file as UTF-8 through an ADO stream #
When another system produces the file, when you cannot re-save it at the source, or when the text mixes scripts, keep the file in UTF-8 and change the reader instead. The ADO stream object ships with Windows and its Charset property names the decoder explicitly:
' Reads a UTF-8 text file into the I/O field tag.
Dim st, txt ' Variants, as VBScript declares them
Set st = CreateObject("ADODB.Stream")
st.Type = 2 ' adTypeText: stream is read as text
st.Charset = "UTF-8" ' the decoder is named, not defaulted
st.Open
st.LoadFromFile path
txt = st.ReadText(-1) ' adReadAll: the whole file
st.Close
SmartTags("IOfieldString") = txt
Type, Charset, Open, LoadFromFile, ReadText and Close are the stream object's documented members, and the numeric values shown are the documented constants for text mode and read-all. To keep the one-line behavior of ReadLine, set the stream's line separator to CRLF and call ReadText(-2), the read-one-line option. If the editor cannot save UTF-8 without a BOM, keep this guard with the script; it removes the BOM character from the front of the string when the read delivers one:
If Left(txt, 1) = ChrW(65279) Then txt = Mid(txt, 2)
The test that proves the change: run the old script and the new one against the same UTF-8 file. The old script fills the field with é, the new one fills it with é. Same file, same tag, so the decoder is the only thing that changed.
Worked example: é from a UTF-8 file on a Windows-1252 runtime #
Inputs, each with its source:
- The letter is é, code point U+00E9, the character in the reported I/O field symptom.
- The bytes on disk are whatever a UTF-8 editor writes for that code point.
- The decoder is
OpenTextFilewith the format argument omitted, documented as ASCII, drawing each byte through Windows-1252, the system ANSI page of the reported Western European runtime (WinCC Runtime Advanced V17).
Rule in words: UTF-8 stores a code point up to U+07FF as two bytes, a lead byte carrying the top bits and a continuation byte carrying the rest. A one-byte decoder ignores the pairing and draws each byte separately, so one letter becomes two glyphs.
Arithmetic, step by step:
- U+00E9 is 233 in decimal and 11101001 in binary.
- Two-byte UTF-8 places the top three bits in the lead byte and the remaining six bits in the continuation byte.
- Lead byte: 111 becomes 110 00011, so the byte is 11000011, which is 0xC3.
- Continuation byte: 101001 becomes 10 101001, so the byte is 10101001, which is 0xA9.
- The file therefore holds 0xC3 0xA9.
- The one-byte decode draws 0xC3 as à and 0xA9 as ©, so the field shows é.
Result: one character stored, two glyphs displayed, the exact reported symptom.
Decision and threshold: read every wrong pair as a verdict. A pair whose first glyph is à means the lead byte arrived alone, so the decode is wrong, whatever the letter behind it. One glyph for each accented letter means the decode is right. The count is the test: two glyphs where the file holds one byte pair means the reader did not decode UTF-8.
Choosing between the two fixes #
- The text stays inside Windows-1252 (accented Latin, the degree sign, section and copyright marks) on a Western European runtime: save the file as ANSI. The script keeps
fs.ReadLineand needs no other edit. - Another system produces the file, or the text must mix scripts: keep UTF-8 at the source and switch the read to the ADO stream with Charset set to UTF-8.
- One project can run both at once, matched file by file: ANSI files through
OpenTextFile, UTF-8 files through the stream.
Control the bytes in the editor when you own the file; control the decode in the script when you do not. Either way the field ends up showing one character for one character.
Questions asked
Why does every wrong pair start with the same first character?
All accented Latin letters in this set encode in UTF-8 with the same lead byte, 0xC3, and a one-byte decode draws 0xC3 as à on its own. Only the second byte changes: 0xA9 draws the copyright sign, 0xA7 draws the section mark, 0xB9 draws a superscript one, 0xB4 draws an acute accent, and 0xA0 draws a non-breaking space, which is why à looks like à followed by an empty gap.
Does the fault look different on a runtime outside Western Europe?
The cause is identical but the wrong glyphs differ, because the system's single-byte ANSI page is not Windows-1252 there. Each UTF-8 byte draws as that locale's glyph, so the pairs look strange in a different way. If you re-save as ANSI on such a runtime, pick the ANSI entry matching that system's locale, because a file saved for the wrong code page swaps letters like ő or ł for unrelated glyphs.
After saving as ANSI, why do some entries still show garbage or question marks?
The text has outgrown one code page. A single ANSI file cannot represent Western accented letters together with Greek, Cyrillic or CJK characters, and anything outside the chosen page arrives as a substitute. Return the source to UTF-8 and use the ADO stream read for those strings, then check that the font applied to the I/O field contains the glyphs, because even a correct decode shows boxes when the font cannot draw them.
How can I check which encoding the file actually uses?
Open it in an editor that reports the encoding in its status bar and trust that report, because a file holding only ASCII letters and this accented set looks nearly identical in both encodings. A UTF-8 file carrying a BOM starts with the three bytes EF BB BF, which a one-byte reader displays as the three characters  before your first real character.


