Jalaj P. Jha

Technical & Miscellaneous Ramblings

VB Forms in Hindi Unicode Fonts

with 44 comments

Most of the applications I came accross are still using old hindi fonts based on ASCII character sets. And when I tried to build one form in Unicode got to know why! As soon as you paste a unicode string on a control or the property window or the code area the string changes to a series of question marks????????

So should I too start using the same old way? I tried searching the net and this is what I came up with.

Though Visual Basic uses UTF-8 for internally handling the unicode text, the development interface that is provides suffers from a shortcoming that spoils all efforts in developing a unicode font based application. While working on property window, or the code window or saving control’s propertybag the Visual Basic takes to convert the strings to charset defined by ANSI loosing the unicode data.

OK, then the alternate solution would be to save the uncode text on a seperate file which would be read and the language text populated during runtime. The catch here is that the controls we intend to use also do the same thing i.e. converting the unicode data to ANSI. However, the corresponding controls available with “Microsoft Forms 2.0 Object Library” are capable of showing the unicode texts.

Create a new project and add a label, commandbutton, textbox, listbox, combobox, checkbox, option button and a toggle button from the Forms 2.0 library controls. The default names of all these would be Label1, CommandButton1, TextBox1, listBox1, ComboBox1, CheckBox1, OptionButton1, ToggleButton1 resp. Change fonts for all these controls to “Arial unicode MS” with font-size 10 or above. “Arial unicode MS” fonts has glyphs for a number of languages including the “Devnagari Script”

Now we would keep our text in an external unicode txt file unitext.txt placed in the same folder as our application. We could have used a resource file too but as our purpose here is just check the feasibility of using unicode fonts on VB forms we will just keep things as discussed. our text file contains the text as below.

लेबल
कमांड बटन
टेक्स्ट बॉक्स
लिस्ट बॉक्स
काँबो बॉक्स
चेक बॉक्स
ऑप्शन बटन
टॉगल बटन

Add a reference to “Microsoft ActiveX Data Objects 2.6 Library”. We would use it’s Stream object to read the text file.

Paste the code below to load event of the form.

Private Sub Form_Load()

    Dim objStream As New ADODB.Stream
    Dim strFullText As String
    Dim varTextLines As Variant

    objStream.Charset = "Unicode"
    objStream.Open
    objStream.LoadFromFile "unitext.txt"

    strFullText = objStream.ReadText
    varTextLines = Split(strFullText, vbCrLf)

    Label1.Caption = varTextLines(0)
    CommandButton1.Caption = varTextLines(1)
    TextBox1.Text = varTextLines(2)
    ListBox1.AddItem varTextLines(3)
    ComboBox1.Value = varTextLines(4)
    CheckBox1.Caption = varTextLines(5)
    OptionButton1.Caption = varTextLines(6)
    ToggleButton1.Caption = varTextLines(7)

End Sub

The code above reads the unitext.txt file and splitting it with each occurrance of vbCrLf gets the text for each control in form of an array which it later assigns it to the controls. The purpose of this post was to demonstrate using unicode font in VB. See what difference it can make to your aplication.

The VB Form with English Text The same form with Hindi Unicode text
unicodefrm1.jpg unicodefrm2.jpg

Written by Jalaj

January 23, 2007 at 5:14 am

44 Responses

Subscribe to comments with RSS.

  1. Sir the information above is very useful for me, many thanks for the above post. I have a query regarding using “Arial Unicode MS” font. I have downloaded it via internet. Its size is 22.2 MB approx., Sir when I use this font to set TextBox1’s Font property to “Arial Unicode MS”, I can’t find any option to set “Devnagari” glyph in font dialog box. Please guide me to solve this problem. The glyph available in list as under: -

    Western
    Japanese
    Hangul
    Hangul(Johnab)
    Chinese_GB2312
    Chinese_BIG5
    Herbrew
    Arabic
    Greek
    Turkish
    Baltic
    Central European
    Cyrillic
    Thai
    Vietnamese

    thankx in addvance…

    Niranjan Bansal

    April 28, 2009 at 1:16 pm

  2. you hv not notes in hivdi

    divya

    March 29, 2009 at 9:45 am

  3. Hi,
    As sugested i have used unicode text box with gujrati shruti font. Everything is working fine except it sows big spaces between the wards. How do i resolve the problem?
    Thanks in advance.

    leena

    December 29, 2008 at 9:25 am

  4. Thank you very much for information.

    Shailesh

    December 29, 2008 at 9:00 am


Leave a Reply