Chilkat HOME Android™ ASP Visual Basic VB.NET C# iOS (IPhone) Objective-C C++ C Unicode C++ Unicode C MFC Delphi DLL Delphi ActiveX FoxPro Java Perl PHP Extension PHP ActiveX Python PowerShell Ruby SQL Server VBScript
Auto-Detect Language and Display Unicode in VB6 TextBox and Label Controls
This example auto-detects the language of a Unicode string and displays the string in a standard VB6 textbox control. This example can be downloaded at http://www.example-code.com/downloads/Vb6UnicodeExample3.zip. A list of Visual Basic 6.0 fonts and the languages each supports is provided at the bottom of this page. ' Demonstrates how to display a Unicode string in any language. ' The Chilkat Charset ActiveX can be downloaded from: ' http://www.chilkatsoft.com/downloads.asp Dim g_Charset As New ChilkatCharset2 ' The CkString is the "Chilkat ASP String Component" which ' can be downloaded from http://www.chilkatsoft.com/download/CkString.zip ' Register the CkString.dll with regsvr32.exe. It is a free ActiveX ' component that can be used in VB6, ASP, FoxPro, Delphi, etc. Dim g_Str As New CkString ' We first have to determine the language. ' Once that is known, set the text control's charset to the appropriate ' value for the language. ' Note: A string cannot contain a mixture of languages (with the exception that ' us-ascii characters can be combined with any language). To display a mixed-language ' string, you truly need a Unicode-capable textbox, listbox, etc. Private Sub DisplayText(filename As String) ' Read utf-8 bytes from a file. Dim textBytes As Variant textBytes = g_Charset.ReadFile(filename) g_Charset.FromCharset = "utf-8" ' Convert to a Unicode string: Dim s As String s = g_Charset.ConvertToUnicode(textBytes) ' What language do we have? ' Use CkString to determine the language. g_Str.Str = s Dim charset As String If g_Str.NumJapanese > 0 Then charset = "Shift_JIS" Text1.Font.Name = "MS UI Gothic" Text1.Font.charset = 128 ElseIf g_Str.NumKorean > 0 Then charset = "ks_c_5601-1987" Text1.Font.Name = "GulimChe" Text1.Font.charset = 129 ElseIf g_Str.NumCentralEuro > 0 Then charset = "windows-1250" Text1.Font.Name = "Arial" Text1.Font.charset = 238 ElseIf g_Str.NumArabic > 0 Then charset = "windows-1256" Text1.Font.Name = "Traditional Arabic" Text1.Font.charset = 178 ElseIf g_Str.NumHebrew > 0 Then charset = "windows-1255" Text1.Font.Name = "David" Text1.Font.charset = 177 ElseIf g_Str.NumCyrillic > 0 Then charset = "windows-1251" Text1.Font.Name = "Arial" Text1.Font.charset = 204 ElseIf g_Str.NumGreek > 0 Then charset = "windows-1253" Text1.Font.Name = "Arial" Text1.Font.charset = 161 ElseIf g_Str.NumThai > 0 Then charset = "windows-874" Text1.Font.Name = "Angsana New" Text1.Font.charset = 222 ElseIf g_Str.NumChinese > 0 Then charset = "gb2312" Text1.Font.Name = "SimSun" Text1.Font.charset = 134 ' An alternative is to use Big5: ' Text1.Font.Name = "MingLiu" 'charset = "big5" 'fontCh = 136 Else charset = "windows-1252" Text1.Font.charset = 0 Text1.Font.Name = "Arial" End If ' Get a displayable string: Dim vbStr As String vbStr = g_Charset.ToVB6(s, charset) ' Display it in a standard VB6 textbox Text1.Text = vbStr End Sub Private Sub Arabic_Click() DisplayText "utf8_arabic.txt" End Sub Private Sub CEuro_Click() DisplayText "utf8_czech.txt" End Sub Private Sub Chinese_Click() DisplayText "utf8_chinese.txt" End Sub Private Sub Greek_Click() DisplayText "utf8_greek.txt" End Sub Private Sub Hebrew_Click() DisplayText "utf8_hebrew.txt" End Sub Private Sub Japanese_Click() DisplayText "utf8_japanese.txt" End Sub Private Sub Korean_Click() DisplayText "utf8_korean.txt" End Sub Private Sub Russian_Click() DisplayText "utf8_russian.txt" End Sub Private Sub Thai_Click() DisplayText "utf8_thai.txt" End Sub Private Sub WEuro_Click() DisplayText "utf8_icelandic.txt" End Sub Private Sub Form_Load() g_Charset.UnlockComponent "Anything for 30-day trial" End Sub Visual Basic 6.0 Font Reference for Various LanguagesArial Languages: Latin1, Greek, Cyrillic, Hebrew, Arabic Code Pages: 1252, 1250, 1251, 1253, 1254, 1255, 1256, 1257, 1258, OEM, 869, 866, 865, 864, 863, 862, 861, 860, 857, 855, 852, 775, 737, 708, 850, 437 Comic Sans MS Languages: Latin1, Greek, Cyrillic Code Pages: 1252, 1250, 1251, 1253, 1254, 1257, Mac Roman Courier New Languages: Latin1, Greek, Cyrillic, Hebrew, Arabic Code Pages: 1252, 1250, 1251, 1253, 1254, 1255, 1256, 1257, 1258, OEM, 869, 866, 865, 864, 863, 862, 861, 860, 857, 855, 852, 775, 737, 708, 850, 437 Georgia Languages: Latin1, Greek, Cyrillic Code Pages: 1252, 1250, 1251, 1253, 1254, 1257, Mac Roman Impact Languages: Latin1, Greek, Cyrillic Code Pages: 1252, 1250, 1251, 1253, 1254, 1257, Mac Roman, 869, 866, 865, 863, 861, 860, 857, 855, 852, 775, 737, 850, 437 Times New Roman Languages: Latin1, Greek, Cyrillic, Hebrew, Arabic Code Pages: 1252, 1250, 1251, 1253, 1254, 1255, 1256, 1257, 1258, OEM, 869, 866, 865, 864, 863, 862, 861, 860, 857, 855, 852, 775, 737, 708, 850, 437 Trebuchet MS Languages: Latin1, Greek, Cyrillic Code Pages: 1252, 1250, 1251, 1253, 1254, 1257, Mac Roman Verdana Languages: Latin1, Greek, Cyrillic Code Pages: 1252, 1250, 1251, 1253, 1254, 1257, 1258, Mac Roman Asian and Middle-Eastern Fonts Japanese Fonts: MS Gothic, MS Mincho, MS UI Gothic, MS PGothic, MS PMincho Korean Fonts: Batang, BatangChe, (select Hangul for script) Gulim, GulimChe, Gungsuh, GungsuhChe, Dotum, DotumChe (GB2312) Simplified Chinese: NSimSun, SimSun, SimHei (Big5) Traditional Chinese: MingLiu, PMingLiu Arabic Fonts: Andalus, Arabic Transparent, Simplified Arabic, Simplified Arabic Fixed, Traditional Arabic Thai Fonts: Angsana New, AngsanaUPC, Browallia New, BrowalliaUPC, Cordia New, CoridaUPC, IrisUPC, DillenialUPC, JasmineUPC, EucrosialUPC, FreesialUPC, LilyUPC Hebrew: David, David Transparent, Aharoni, Miriam, Rod, Rod Transparent, Miriam Fixed, Miriam Transparent, FrankRuehl, Levenim MT, Narkisim
|
© 2000-2013 Chilkat Software, Inc. All Rights Reserved.