Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

October 6, 2005

In Visual Basic, Strings are Unicode

Q:
I tried to find an example usage of charset control in visual basic but i couldn’t succeed. I’m trying to show unicode characters (Turkish, Russian, Arabic, etc) on command button, treeview control and listview control.

I’m using the following code to test:

Dim cs As New ChilkatCharset2Lib.ChilkatCharset2
cs.UnlockComponent "********"
cs.FromCharset = "windows-1254″
cs.ToCharset = "windows-1250″
MsgBox cs.ConvertData("đţ")
MsgBox cs.ConvertToUnicode("đţ")
MsgBox cs.ConvertHtml("đţ")

actually I tested with changing ToCharset and FromCharset also but I couldn’t get the result correctly. The characers there are two Turkish characters.

Is there any way to do this? Can you send me any sample?

ANSWER:
Strings in Visual Basic are Unicode. The only way to work with byte data representing characters in a particular charset encoding is with a byte array.

When you pass "đţ" to ConvertData, you are passing a Unicode string (i.e. each character is represented by 2-bytes of data.) However, your code is telling the conversion component that you are passing "windows-1254″ (1 byte/char) data, but you are NOT. Also, ConvertData returns a byte array (in a Variant), but MsgBox is expecting a string (Unicode of course).

If you are trying to display Unicode characters in VB6, your best course of action is to use the Microsoft Forms 2.0 controls (fm20.dll) instead of the default controls. These are Unicode-capable controls (text box, label, list box, etc.) that can display strings (Unicode) in any language. The default VB6 controls do not support Unicode, even though VB6 strings *are* Unicode, go figure! For me, internationalization is one of the biggest reasons for switching to .NET.


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.