CodePage Property  
 

Gets and sets the code page used when converting text to and from Unicode.

Syntax

object.CodePage [= value ]

Remarks

The CodePage property is an integer value which specifies how text is encoded. Any valid code page identifier may be specified. Some common values are:

Value Description
0 Strings should be converted using the ANSI code page for the current locale.
1 Strings should be converted using the system default OEM code page. The OEM code page typically contains characters that are used by console applications and are based on character sets commonly used by MS-DOS. You should not use this code page unless you know the file has text which includes OEM characters.
1252 Strings should be converted using the Windows ANSI code page for western European languages. This code page is commonly used by legacy Windows applications for English and some other western languages. It should be noted that while this code page is similar to ISO 8859-1 character encoding, it is not identical.
28591 Strings should be converted using the ISO 8859-1 code page for western European languages. This code page is commonly referred to as Latin-1 and is similar to the Windows 1252 code page.
65000 Strings should be converted using the obsolete UTF-7 encoding. It is not recommended that you use this code page unless you know the file contains UTF-7 encoded text.
65001 Strings should be converted using UTF-8 encoding. If this code page is Because UTF-8 is backwards compatible with the ASCII character set, it is safe to use this encoding option when a file contains ASCII text. This is the default code page used by the control.

A complete list of available code page identifiers External Link can be found in Microsoft's documentation for the Win32 API.

This property value directly corresponds to Windows code page identifiers, and will accept any valid code page in addition to the values listed above. Setting this property to an invalid code page will result in an error.

Although strings in Visual Basic are internally managed as Unicode, the default common controls used in Visual Basic 6.0 do not support Unicode. Those controls, such as buttons, text boxes and labels, will automatically convert the Unicode text to ANSI using the current code page. This means that text in the end-user's native language (depending on system settings) may display correctly, although text in other languages using different character sets may not. Also note that the VB6 IDE is not Unicode aware and may display corrupted string values or invalid characters, such as with tooltip values when debugging.

For Unicode support in Visual Basic 6.0, it's recommended that you use third-party controls. An alternative that some developers have used is the Microsoft Forms 2.0 Object Library (FM20.DLL) that is part of Microsoft Office. It includes a collection of controls that support Unicode, however they are not redistributable and Microsoft has stated that their use with VB6 is unsupported. Note that even with a Unicode-aware UI control, you also need to select a display font which supports Unicode characters, such as Segoe UI.

If you wish to convert text between UTF-8 and native Unicode strings, use the StrToUtf8 and Utf8ToStr methods.

Data Type

Integer (Int32)

See Also

DecodedText Property, EncodedText Property, ConvertFile Method, FilterUnicode, StrToUtf8, Utf8ToStr