Section E.6. Using Unicode


E.6. Using Unicode

Visual Studio uses Unicode UTF-16 encoding to represent all characters. Figure E.3 uses Visual Basic to display the text "Welcome to Unicode!" in eight different languages: English, French, German, Japanese, Portuguese, Russian, Spanish and Traditional Chinese.

Figure E.3. Windows application demonstrating Unicode encoding.

  1  ' Fig. F.3: Unicode.vb  2  ' Using Unicode encoding.  3  Public Class FrmUnicodeDemo  4     Private Sub FrmUnicodeDemo_Load(ByVal sender As System.Object, _  5        ByVal e As System.EventArgs) Handles MyBase.Load  6        'English  7        lblEnglish.Text = ChrW(&H57) & ChrW(&H65) & ChrW(&H6C) & _  8           ChrW(&H63) & ChrW(&H6F) & ChrW(&H6D) & ChrW(&H65) & _  9           ChrW(&H20) & ChrW(&H74) & ChrW(&H6F) & ChrW(&H20) & _ 10           "Unicode" & ChrW(&H21) 11 12        ' French 13        lblFrench.Text = ChrW(&H42) & ChrW(&H69) & ChrW(&H65) & _ 14           ChrW(&H6E) & ChrW(&H76) & ChrW(&H65) & ChrW(&H6E) & _ 15           ChrW(&H75) & ChrW(&H65) & ChrW(&H20) & ChrW(&H61) & _ 16           ChrW(&H75) & ChrW(&H20) & "Unicode" & ChrW(&H21) 17 18        ' German 19        lblGerman.Text = ChrW(&H57) & ChrW(&H69) & ChrW(&H6C) & _ 20           ChrW(&H6B) & ChrW(&H6F) & ChrW(&H6D) & ChrW(&H6D) & _ 21           ChrW(&H65) & ChrW(&H6E) & ChrW(&H20) & ChrW(&H7A) & _ 22           ChrW(&H75) & ChrW(&H20) & "Unicode" & ChrW(&H21) 23 24        ' Japanese 25        lblJapanese.Text = "Unicode " & ChrW(&H3078) & _ 26           ChrW(&H3087) & ChrW(&H3045) & ChrW(&H3053) & _ 27           ChrW(&H305D) & ChrW(&H21) 28 29        ' Portuguese 30        lblPortuguese.Text = ChrW(&H53) & ChrW(&HE9) & ChrW(&H6A) & _ 31           ChrW(&H61) & ChrW(&H20) & ChrW(&H42) & _ 32           ChrW(&H65) & ChrW(&H6D) & ChrW(&H76) & _ 33           ChrW(&H69) & ChrW(&H6E) & ChrW(&H64) & _ 34           ChrW(&H6F) & ChrW(&H20) & "Unicode" & ChrW(&H21) 35 36        ' Russian 37        lblRussian.Text = ChrW(&H414) & ChrW(&H43E) & ChrW(&H431) & _ 38           ChrW(&H440) & ChrW(&H43E) & ChrW(&H20) & _ 39           ChrW(&H43F) & ChrW(&H43E) & ChrW(&H436) & _ 40           ChrW(&H430) & ChrW(&H43B) & ChrW(&H43E) & _ 41           ChrW(&H432) & ChrW(&H430) & ChrW(&H442) & _ 42           ChrW(&H44A) & ChrW(&H20) & ChrW(&H432) & _ 43           ChrW(&H20) & "Unicode" & ChrW(&H21) 44 45        ' Spanish 46        lblSpanish.Text = ChrW(&H42) & ChrW(&H69) & ChrW(&H65) & _ 47           ChrW(&H6E) & ChrW(&H76) & ChrW(&H65) & _ 48           ChrW(&H6E) & ChrW(&H69) & ChrW(&H64) & _ 49           ChrW(&H61) & ChrW(&H20) & ChrW(&H61) & _ 50           ChrW(&H20) & "Unicode" & ChrW(&H21) 51 52        ' Traditional Chinese 53        lblChinese.Text = ChrW(&H6B22) & ChrW(&H8FCE) & _ 54           ChrW(&H4F7F) & ChrW(&H7528) & ChrW(&H20) & _ 55           "Unicode" & ChrW(&H21) 56     End Sub ' FrmUnicodeDemo_Load 57  End Class ' FrmUnicodeDemo 

The first welcome message (lines 13-16) contains the hexadecimal codes for the English text. The Code Charts page on the Unicode Consortium Web site contains a document that lists the code values for the Basic Latin block (or category), which includes the English alphabet. The hexadecimal codes in lines 13-14 equate to "Welcome." When using Unicode characters in Visual Basic, the format &Hyyyy is used, where yyyy represents the hexadecimal Unicode encoding. For example, the letter "W" (in "Welcome") is denoted by &H57. [Note: The actual code for the letter "W" is &H0057, but Visual Studio removes the two zeros.] Line 15 contains the hexadecimal for the space character (&H20). The hexadecimal value for the word "to" is on line 15 and the word "Unicode" is on line 14. "Unicode" is not encoded because it is a registered trademark and has no equivalent translation in most languages. Line 16 also contains the &H21 notation for the exclamation mark (!).

The remaining welcome messages (lines 18-61) contain the hexadecimal codes for the other seven languages. The code values used for the French, German, Portuguese and Spanish text are located in the Basic Latin block, the code values used for the Traditional Chinese text are located in the CJK Unified Ideographs block, the code values used for the Russian text are located in the Cyrillic block and the code values used for the Japanese text are located in the Hiragana block.

[Note: To render the Asian characters in a Windows application, you would need to install the proper language files on your computer. To do this, open the Regional Options dialog from the Control Panel (Start > Settings > Control Panel). At the bottom of the General tab is a list of languages. Check the Japanese and the Traditional Chinese checkboxes and press Apply. Follow the directions of the install wizard to install the languages. For additional assistance, visit www.unicode.org/help/display_problems.html.]



Visual BasicR 2005 for Programmers. DeitelR Developer Series
Visual Basic 2005 for Programmers (2nd Edition)
ISBN: 013225140X
EAN: 2147483647
Year: 2004
Pages: 435

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net