I’m having a problem trying to output the content of some variables in vb6 into a text file. The thing is that when a special character from extended ASCII appears as ä, ü, á it is transformed in the output to the matching basic ASCII char like a, u, a.
I’ve tried to export it like UTF-8 and then the character is shown correctly, but I need the output to be ASCII. Also, looks strange for me that the filename can normally contain this chars (ä, ü, á…) without sustitution.
Can this be because “ASCII” charset is just the basic and not the extended? Maybe because of the CodePages configured in Windows? I’ve tried with a couple of them (German, English) with the same result.
This is the code I’m using:
Set fileStream = New ADODB.Stream
If Not fileStream Is Nothing Then
inputString = textPreAppend + inputString
fileStream.charSet = "ASCII"
fileStream.Open
fileStream.WriteText inputString
fileStream.Flush
fileStream.SaveToFile fileName, adSaveCreateOverWrite
fileStream.Flush
fileStream.Close
End If
Set fileStream = Nothing
Thanks in advance!
Both PRB: Charset Property of ADO Stream Object May Require Microsoft Internet Explorer Upgrade and Charset Property (ADO) suggest that ADO CharSet values are those listed under
HKEY_CLASSES_ROOT\MIME\Database\Charsetbut that clearly is not the entire story.For example both values “ascii” and “us-ascii” are listed there as aliases of “iso-8859-1” however running with my locale set to U.S. English they act like a 7-bit ASCII MIME type. They’d almost have to, since there is nothing else provided for requesting 7-bit ASCII encoding anyway.
This produces the result you seem to want:
Output:
We have to assume that asking for “ascii” (the values are all lowercased though clearly are not case-sensitive) means 7-bit ASCII, perhaps localized.
Using UTF-8 is a bad idea unless you want UTF-8. While a lot of *nix systems pretend there is no difference, the Stream will write a BOM and of course those extended (non-ASCII) characters are multibyte encoded.