PRB: Extended ASCII Characters Displayed as "?" in Win98ID: Q216211
|
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 or Windows NT SP4. The same application works correctly under Windows 95 or Windows NT (pre-SP4).
The problem is caused by the UNICODE to ANSI conversion. The code page 1252 (ANSI) used by Windows 98 and NT 4.0 SP4 is different than the one used by Windows 95 and 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:
Dim str as String
str = Chr$(&H80)
MsgBox AscW(str)
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.
The following samples use a property bag to demonstrate the problem.
Option Explicit
Dim m_Test As String
Public Property Get Test() As String
Test = m_Test
End Property
Public Property Let Test(ByVal New_Test As String)
m_Test = New_Test
PropertyChanged "Test"
End Property
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
m_Test = PropBag.ReadProperty("Test", "")
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
MsgBox "Writing Test..."
Dim a As String
a = "bad" & Chr(128) & "bad"
Call PropBag.WriteProperty("Test", a, "")
End Sub
Option Explicit
Private Sub Form_Load()
MsgBox UserControl11.Test & vbCrLf & "Asc for bad Char:" & Asc(Mid(UserControl11.Test, 4, 1))
End Sub
Option Explicit
Dim m_Test() As Byte
Public Property Get Test() As String
Test = StrConv(m_Test, vbUnicode, 1033)
End Property
Public Property Let Test(ByVal New_Test As String)
m_Test = StrConv(New_Test, vbFromUnicode, 1033)
PropertyChanged "Test"
End Property
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
m_Test = PropBag.ReadProperty("Test", "")
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
MsgBox "Writing Test..."
Dim a As String
Dim b() As Byte
a = "bad" & Chr(128) & "bad"
b = StrConv(a, vbFromUnicode, 1033)
Call PropBag.WriteProperty("Test", b, "")
End Sub
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:
Q197368 Code Page 1252 Includes New Characters
Additional query words:
Keywords : kbString kbUnicode kbVBp kbVBp500 kbVBp600 kbWinOS95 kbWinOS98 kbNTOS400sp4 kbGrpVB
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: March 11, 1999