Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Display Japanese in VB6 on Any Computer Regardless of LocaleThis example applies to any language: Japanese, Chinese, Korean, Hebrew, Arabic, Czech, Vietnamese, Thai, Russian, etc. Note: This only works with the label and textbox controls. Unfortunately, VB6 has different internal behavior for the button text, checkboxes, frame captions, and other places where text can be displayed, and this method does not work for those. Our previous example discussed what you absolutely need to know if you are intending to display foreign characters using the standard VB6 textbox and label controls. In summary: VB6 stores strings as Unicode. When a textbox or label control displays a string, it first does an internal conversion from Unicode to the ANSI charset of the computer on which its running. It then interprets the resulting bytes according to the Font.Charset property of the control. You would think that nothing more is required than to set the Font.Charset equal to the correct integer value for the language to be displayed and then set the control's Text property equal to the Unicode string. This works if you're computer's locale is the same as the language of the text being displayed (i.e. your displaying Chinese text on a Chinese computer, or Greek text on a Greek locale computer). However, it does not work when the locale of the computer is something different. PS> Here are the values for Font.Charset required for different languages: 128 Japanese, Shift_JIS (Japanese Industry Standard) 129 Korean, ks_c_5601-1987 130 Korean, johab 134 Simplified Chinese, gb2312 - Mainland China(PRC) and Singapore 136 Traditional Chinese, big5 - Taiwan and Hong Kong 161 Greek, windows-1253 162 Turkish, windows-1254 163 Vietnamese, windows-1258 177 Hebrew, windows-1255 178 Arabic, windows-1256 186 Baltic, windows-1257 204 Cyrillic, windows-1251 - Russia, Belarus, Ukraine... 222 Thai, windows-874 238 Central/Eastern European, windows-1250
Introducing the ToVB6 MethodThe Chilkat Charset ActiveX can be downloaded HERE The Chilkat Charset component includes a "ToVB6" method that makes it possible to display a Unicode string for a particular language in a standard textbox or label control. It will work correctly regardless of the locale of the computer on which it is running. Rather than setting the control's Text property equal to the Unicode string directly, you should set it to the string returned by ToVB6. Here is an example, which can be downloaded at http://www.example-code.com/downloads/vb6UnicodeExample2.zip
Dim cc As New ChilkatCharset2
cc.UnlockComponent "anything for 30-day trial"
' Load a Japanese string encoded in utf-8 into memory:
Dim utf8Bytes As Variant
utf8Bytes = cc.ReadFile("utf8_japanese.txt")
' Convert it to a Unicode string:
Dim japaneseUni As String
cc.FromCharset = "utf-8"
japaneseUni = cc.ConvertToUnicode(utf8Bytes)
' We now have a Unicode string with Japanese characters.
' Set the Font.Charset on our textboxes for Japanese:
Text1.Font.Charset = 128
Text2.Font.Charset = 128
' You would expect that setting Text1.Text = japaneseUni
' would display the Japanese characters correctly.
' It does on a computer in Japan, but not on
' non-Japanese computers:
Text1.Text = japaneseUni
' Why??? Because VB6 is (internally) converting
' Unicode to ANSI first and then interpreting the ANSI
' bytes according to the Font.Charset setting.
' Text1.Text will display question marks on non-Japanese
' computers because the implicit (and internal)
' Unicode-to-ANSI conversion fails. (Japanese characters
' are not representable in Windows-1252.)
' What you need instead is to convert the Unicode string
' to another Unicode string such that when VB6 does
' the Unicode-to-ANSI conversion, you end up with Shift_JIS
' regardless of the locale of the computer.
' This is exactly what the ToVB6 method does:
Dim correctForDisplay As String
correctForDisplay = cc.ToVB6(japaneseUni, "Shift_JIS")
Text2.Text = correctForDisplay
' Note: The correctForDisplay string should only be used for displaying
' the Japanese string.
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.