Chilkat Examples
Languages

Chilkat Software

 

Charset 101

 

VB6 String Displays ????'s - Why?

What does it mean when a "?" is displayed instead of the character I expected? The reason is that standard controls (textbox, label, listbox, etc.) in Visual Basic 6.0 are not Unicode capable. Although strings in VB6 are fully Unicode, it is not possible to render every Unicode character in a standard VB6 control. A VB6 control can render only the characters in a single multibyte charset at a time -- meaning that it's not possible to mix languages. You cannot display Greek with Russian, or Hebrew with Japanese. English may be mixed with any language because typically us-ascii (0x00 - 0x7F) maps directly to all ANSI charsets. It's only the bytes from 0x80 and above that are different. (in general)

When Visual Basic encounters a Unicode character it cannot display, it substitutes a question mark character.

The following test program will attempt to display 3 characters: The Euro symbol, an Eastern-European character, and a Russian (Cyrillic) character. The computer's ANSI code page (used for this testing) is Windows-1252, i.e. Western European, therefore we'd expect the Eastern European character and Russian character to not display properly.

The characters to be tested are:

    ' Notice we're using little-endian byte ordering.
    Dim y(5) As Byte
    y(0) = &HAC
    y(1) = &H20

    y(2) = &H7C
    y(3) = &H1
    
    y(4) = &H2
    y(5) = &H4
    
    Text1.Text = y

The result is that the Euro symbol displays OK, the ż displays as a "z" (VB6 must have made an approximation), and the Cyrillic character displays as a question mark (no approximation possible).

It's possible to tell the VB6 control to use a specific code page. In this case, 204 is the "VB6 secret code" for Cyrillic:

    Dim y(5) As Byte
    y(0) = &HAC
    y(1) = &H20

    y(2) = &H7C
    y(3) = &H1
    
    y(4) = &H2
    y(5) = &H4
    
    Text1.Font.Charset = 204
    Text1.Text = y

Now the Cyrillic character displays correctly, the "z" is still an approximation, but the Euro character is shown as a "?". Furthermore, Cyrillic is right-to-left so the order of the chars is reversed.

© 2000-2022 Chilkat Software, Inc. All Rights Reserved. ..