Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

When trying to write double byte characters to a newly created file why do I encounter the error *** Error: Cannot write double byte characters("String Name) into an ANSI file?

When trying to write double byte characters to a newly created file why do I encounter the error *** Error: Cannot write double byte characters("String Name) into an ANSI file?

When using the functions FileWriteLine() or FileWriteValue() to write double byte characters to a file you may encounter the above error. For example in the snippet of code below; when I attempt to write Japanese Double Byte Characters to a .txt file:


[-] testcase WriteLine () appstate none
[ ]
[ ] HFILE FileHandle
[ ] FileHandle = FileOpen ("C:\\mydata.txt", FM_APPEND)
[ ]
[ ] FileWriteLine (FileHandle, "????????????????????????????????????????")
[ ]
[ ] FileClose (FileHandle)

It will result in the error message:

[ ] *** Error: Cannot write double byte characters(????????????????????????????????????????) into an ANSI file

The reason for this error is that the file “mydata.txt” was created in Notepad using the default ANSI encoding. ANSI is normally a single byte encoding where 256 character codes (0..255) define all available characters for a language. In order for the file to accept Double Byte characters the encoding will have to be set to a file type encoding which supports Double Bytes, such as Unicode Encoding. This can be done one of two ways

1) Set the File Type parameter of the function “FileOpen” to a encoding which supports the double byte character set (either FT_UNICODE or FT_UTF8); like so:

FileHandle = FileOpen ("C:\\mydata.txt", FM_APPEND, NULL, FT_UNICODE)

2) Open the .txt file in a text editor outside of SilkTest and then save the file with the encoding set to "Unicode" or "UTF8" .

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 20:39
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.