Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display Unicode characters in VB6? [duplicate]

Tags:

unicode

vb6

chr

Possible Duplicate:
What’s the best option to display Unicode text (hebrew, etc.) in VB6

What is the correct way to display the unicode character 9646 (BLACK VERTICAL RECTANGLE) in VB6?

When I try ChrW(9646) it displays ?.

like image 596
CJ7 Avatar asked Dec 29 '12 10:12

CJ7


People also ask

Does VB6 support Unicode?

Internally, VB6 stores strings as Unicode. Your VB6 program is capable of manipulating strings in any language containing any character -- whether it's Chinese, Japanese, Icelandic, Arabic, etc. It's fully Unicode capable.

What is Char data Type in Visual Basic?

Visual Basic provides character data types to deal with printable and displayable characters. While they both deal with Unicode characters, Char holds a single character whereas String contains an indefinite number of characters.


2 Answers

Here is a tutorial to explore. Take a look at this article for the black vertical rectangle.

Assuming Unicode is turned on, send the following string to a window to display:

Wchar_t mStr[] = {9646,0,0};

Reference. This code snippet and reference is more inlined with C++. Where you would turn off/on UNICODE in Visual C++ using following steps:

  1. Open your project in VS2008/2010;

  2. Right click the project in Solution Explorer and click Properties;

  3. Select Configuration Properties-> General, select Character Set and change the current value to Use Multi-Byte Character Set. (turning off)


Good article aboubt displaying UNICODE in VB.

When you are working with a textbox control in a Form, add the Microsoft Forms 2.0 Object Library as a reference library. This component provides Unicode supportted controls, such as: textbox, label, command button,list box, combo box, checkbox, radio button, toggle button, image, tabstrip, and multiple page control.

Working with VB6 and displaying non-us-ANSI characters you need 3 main things to understand:

  • Internally, VB6 stores strings as Unicode.
  • When displaying a string, the standard VB6 textbox and label controls do an implicit (and internal) conversion from Unicode to ANSI.
  • The standard VB6 textbox and label controls display the ANSI bytes according to a character encoding that you can specify.

After the Unicode-to-ANSI conversion, VB6 then attempts to display the character data according to the control's Font.Charset property, which if left unchanged is equal to the ANSI charset. Changing the control's Font.Charset changes the way VB6 interprets the "ANSI" bytes. In other words, you're telling VB6 to treat the bytes as some other character encoding instead of "ANSI".

For e.g. consider trying to display a Unicode Japanese string on an English computer: You set the Font.Charset = 128 (for Japanese), but your Unicode string displays as all question mark characters. It's because VB6 is first trying to convert your Japanese Unicode string to ANSI, which is Windows-1252 for English computers. Japanese characters are not representable in Windows-1252. Each character fails to convert and is replaced with a question mark. for e.g. Selecting the Japanese script in the TextBox control's property settings is the same as setting the Font.Charset at runtime.

As Jukka said Font plays a vital role showing UNICODEs given the availability of the characters within a Font. As Hans said, glyph unsupported Font produces a rectangle. So you need to make sure the Font you select is capable of rendering glyphs. For e.g. MS Sans Serif font does not render ƒ (LATIN SMALL LETTER F WITH HOOK, 2-byte Unicode value is 0x0192), so you'll see a thin solid rectangular box in its place. However on Windows, there are very few fonts with a wide enough character repertoire to represent Chinese..

In the following code the Font Name () is set during Run Time along the Font CharSet

Charset properties:

134     Simplified Chinese, gb2312 - Mainland China(PRC) and Singapore
136     Traditional Chinese, big5 - Taiwan and Hong Kong

Code:

Sub changeToUniCodes()
Dim strTxt2 As String    

UserForm1.TextBox2.Font.Charset = 134    '--CHINESESIMPLIFIED_CHARSET
UserForm1.TextBox2.Font.Name = ChrW(&H5B8B) + ChrW(&H4F53) '-- 宋体 SimSun font

UserForm1.TextBox2.Text = ChrW(37446)
strTxt2 = UserForm1.TextBox2.Text
'notice that ChrW(9246) produces a different character in Chinese
UserForm1.TextBox2.Text = strTxt2 & " " & ChrW(9246)
End Sub

Output in VBE IDE: You may give it a try in VB6 form as well.

enter image description here

After all the above writing, I noticed this MSDN article. Well at least it's VB confirmation :D

like image 111
bonCodigo Avatar answered Sep 19 '22 08:09

bonCodigo


What you need is to use "Unicode aware" controls. VB6 only came with a few of these, though in Vista and later or XP (Tablet Edition only unless you use the non-Ink redist version of this library) the InkEdit control can do this.

InkEdit1.Text = ChrW$(9646)

Note the $ which indicates a function returning a String instead of a Variant with one embedded in it.

An InkEdit control is really an enhanced RichTextBox that supports ink entry as well as typing on ink-enabled systems. It is also a Unicode control, and one that supports Unicode properties such as .Text.

The standard MSHFlexGrid, DataGrid, and a few other controls are also Unicode-aware.

See http://www.alanwood.net/unicode/geometric_shapes.html for characters like the one in question. You can basically ignore the jibber-jabber about ANSI, Charset, etc. It is relevant but not applicable here.

▮ 9646 ▮ 25AE BLACK VERTICAL RECTANGLE

like image 39
Bob77 Avatar answered Sep 21 '22 08:09

Bob77