Home > Articles > Programming > Visual Basic

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Character Sets

In theory, a character set is just another name for a code page; in this case, a character set is the encoding that describes the relationship between these code points and the glyphs that exist within fonts (see Table 2). The main difference between character sets and code pages, however, is that the number of character sets is much more manageable. At first, this might seem like a good thing, but when you consider the fact that the operating system will have to do the work to map between the code page values and the font character sets, suddenly it seems a lot more complicated than it needs to be. Luckily, unless you are writing your own fonts, this is one issue that you can safely ignore; simply set the appropriate character set. Font creation is an interesting but complicated topic, which is (thankfully) beyond the scope of this book.

Table 2 Character Sets and Their Values

Character Set Name

Value

ANSI_CHARSET

0

DEFAULT_CHARSET

1

SYMBOL_CHARSET

2

SHIFTJIS_CHARSET

128

HANGEUL_CHARSET

129

GB2312_CHARSET

134

CHINESEBIG5_CHARSET

136

OEM_CHARSET

255

JOHAB_CHARSET

130

HEBREW_CHARSET

177

ARABIC_CHARSET

178

GREEK_CHARSET

161

TURKISH_CHARSET

162

VIETNAMESE_CHARSET

163

THAI_CHARSET

222

EASTEUROPE_CHARSET

238

RUSSIAN_CHARSET

204

MAC_CHARSET

77

BALTIC_CHARSET

186

Character sets are available to Visual Basic developers through the CharSet property of the StdFont object, which is defined as an automation type in stdole2.tlb (referenced in every VB project) and used by the Font property of all the VB form and control types. In Visual C++, character sets are defined in the wingdi.h header file. Unfortunately, VB does not define constants or an Enum for character sets, but you can create one yourself from Table 2, creating a ValidCharsets Enum:

Public Enum ValidCharsets
    ANSI_CHARSET = 0
    DEFAULT_CHARSET = 1
    SYMBOL_CHARSET = 2
    SHIFTJIS_CHARSET = 128
    HANGEUL_CHARSET = 129
    GB2312_CHARSET = 134
    CHINESEBIG5_CHARSET = 136
    OEM_CHARSET = 255
    JOHAB_CHARSET = 130
    HEBREW_CHARSET = 177
    ARABIC_CHARSET = 178
    GREEK_CHARSET = 161
    TURKISH_CHARSET = 162
    VIETNAMESE_CHARSET = 163
    THAI_CHARSET = 222
    EASTEUROPE_CHARSET = 238
    RUSSIAN_CHARSET = 204
    MAC_CHARSET = 77
    BALTIC_CHARSET = 186
End Enum

The StdFont object has many uses beyond just enabling you to set font attributes.

  • + Share This
  • 🔖 Save To Your Account