PRB: Extended ASCII Characters Displayed as "?" (216211)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 5.0
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q216211 SYMPTOMS
If you use extended ASCII characters in a Visual Basic project and build the project under Windows 95 or Windows NT (pre-SP4), some of the characters become "?" when the application is run under Windows 98, Windows Me, Windows NT SP4, or Windows 2000. The same application works correctly under Windows 95 or Windows NT (pre-SP4).
CAUSE
The problem is caused by the UNICODE to ANSI conversion. The code page 1252 (ANSI) used by Windows 98, Windows Me, Windows NT 4.0 SP4, and Windows 2000 is different than the one used by Windows 95 and Windows NT 4.0 (pre-SP4), so the transformation for extended ASCII characters is different. For example, the following code will display 128 in Windows 95 but 8364 in Windows 98, Windows Me, and Windows 2000:
Dim str as String
str = Chr$(&H80)
MsgBox AscW(str)
When you store a string containing Chr$(&H80) in a property bag, a file, or declare it as a const value on a Windows 95 computer, a two-byte value of 128 will be stored for Chr$(&H80). If you then read the information on a Windows 98, Windows Me, or Windows 2000 computer, the operating system will be unable to find a match between the UNICODE value 128 and an ANSI character. As a result, "?" will be used to represent that character.
RESOLUTION
Use a byte array instead of a string to store the extended ASCII characters if you need to use them. You can use either the CopyMemory API or the StrConv function to convert the string to a byte array.
REFERENCES
For additional information about the new code page 1252 (ANSI) and why it is changed, please see the following article in the Microsoft Knowledge Base:
Modification Type: | Major | Last Reviewed: | 5/13/2003 |
---|
Keywords: | kbprb kbString kbUnicode KB216211 |
---|
|