Jalaj

January 23, 2007

VB Forms in Hindi Unicode Fonts

Filed under: Application, Indian Languages, Visual Basic — Jalaj @ 5:14 am

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

26 Comments »

  1. Very Informative. But when i stored the same text strings in a database, and when i try to display the same data, it is again come as a ????? .

    Do you have any solution for that.

    Regards
    Amit

    Comment by Amit Pandey — April 3, 2007 @ 6:23 am

  2. Its a very Good Question from Amit?? Lot of people face these issue. if you could put up a sample to store and retrive the same text from database its very useful.

    regards

    Comment by phil — April 4, 2007 @ 11:28 am

  3. The problem arises mainly due to some functions converting the text to ANSI before storing or displaying data.

    Suggessions accepted, and I will try to include a post on storing, retrieving and displaying unicode data, asap.

    Comment by Jalaj — April 5, 2007 @ 4:03 am

  4. Thank you very much i shall be very greatful!! Thanks for your kind response

    Comment by phil — April 9, 2007 @ 5:42 am

  5. when you got the solution, kindly post the URL as comment here, or if you don’t mind kindly drop me a mail.

    Regards
    Amit

    Comment by Amit Pandey — April 11, 2007 @ 10:03 am

  6. [...] Unicode Data in Databases This post is in continuation to my earlier post VB Forms in Hindi Unicode Fonts following a few comments regarding improper display of stored [...]

    Pingback by Storing Unicode Data in Databases « Jalaj — April 12, 2007 @ 11:31 am

  7. Unicode data storage issue as posted in comments by Amit & Phil has been taken in recent post Storing Unicode Data in Databases

    Comment by Jalaj — April 12, 2007 @ 11:35 am

  8. Sir
    i am Astt. Programer
    Unicode Fount(mangal)to English at visual basic 6.0

    Comment by Shrikant Agrawal — April 15, 2007 @ 3:29 pm

  9. good solution

    also i need to convert utf-8 data to ansi mode
    how can i do this by replacing all the special charactors to entity values

    pls. help

    Comment by Dinal — May 9, 2007 @ 10:23 am

  10. [...] it, but hope this would clarify on all steps required to get going. Let’s start with my post VB Forms in Hindi Unicode Fonts. Here I designed a form where all text were in English. As soon as the form was loaded, a text file [...]

    Pingback by Changing UI Language during Runtime « Jalaj — May 24, 2007 @ 12:17 pm

  11. Thank you very much.
    U solved our big problem

    Comment by Bharat Patil — July 6, 2007 @ 12:30 pm

  12. This is very useful, but if i want to mak customize software as according to my language.
    how will vb support it.

    Comment by Makrand — July 30, 2007 @ 11:42 am

  13. Has anyone found a way of displaying unicode text in the Form Caption?

    Comment by Les — September 7, 2007 @ 1:00 pm

  14. Dear sir
    I follow all the steps mentioned. At runtime error no ‘3002′ with message “file couldnot be opened” is flashed.

    pl. provide the solution.

    Regards
    Pankaj

    Comment by Pankaj — November 1, 2007 @ 5:30 am

  15. Hi
    I followed the steps mentioned.But runtime error no 3002 with message file could not be opened is flashed.

    Pl. provide solution.

    Regards
    Pankaj

    Comment by Pankaj — November 1, 2007 @ 5:33 am

  16. Problem might be one of the two
    1) The text file is not present in the same folder as the executable.
    2) The text file is already opened by some other application.

    Comment by Jalaj — November 1, 2007 @ 6:13 am

  17. Dear Sir
    Thanks for your response.It is vary useful for me.

    I create a text file using kruti 011 font.When i select font arial unicode ms the hindi text is changed.
    Pl. advice me the font used in creating your text file “unicode.txt”

    waiting for your responce.
    regards
    pankaj

    Comment by Pankaj Kumar — November 7, 2007 @ 12:30 pm

  18. Dear Sir
    Thanks for your response.It is vary useful for me.

    I create a text file using kruti 011 font.When i select font arial unicode ms the hindi text is changed.
    Pl. advice me the font used in creating your text file “unicode.txt”

    waiting for your responce.
    regards
    pankaj

    Comment by Pankaj — November 8, 2007 @ 8:32 am

  19. @Pankaj

    Kriti011 that you were using is a non-unicode hindi font… You feel how unicode and others differ please have a look at http://www.google.com/transliterate/indic/

    Check the unicode text output that results from transliteration …

    Comment by Jalaj — November 14, 2007 @ 4:07 am

  20. This is Jamal ahmad Ansari this is very good information provided by you
    i am software engineer earlier i have worked in vb6.0 now i have working in PHP
    i am trying to create a application software that store hindi character in the database i had tried in vb6.0 but when we insert form data into database error is generated and application is crashed

    can you provide me some help

    Thanks

    Comment by Jamal Ahmad — November 27, 2007 @ 8:15 pm

  21. See if the link below helps otherwise the details would be required to guess for what could be the reason.

    jalaj.net/2007/04/12/storing-unicode-data-in-databases/

    Comment by Jalaj — November 28, 2007 @ 1:55 pm

  22. me abhi seekh raha hu kuch baatya ki kese sekhe vb

    Comment by Ganesh Kumar Daheriy — January 16, 2008 @ 4:05 pm

  23. How can we use unicode texts using resource file

    Comment by Balaji — February 2, 2008 @ 7:39 am

  24. Please help me in using unicode text(Chinese) using resource file.

    Thanks in Advance.

    Comment by Balaji — February 2, 2008 @ 7:40 am

  25. it not sufficient to me i want to change the menu and toolbar caption

    Comment by amit mittal — March 19, 2008 @ 6:40 am

  26. hello,
    if we r already having a form designed and now want to change it in hindi, then how can we convert existing labels, buttons in microsoft forms 2.0 object library’s labels and button?,
    or we have to redesign it which will take more time n a tuff work.
    plz help..

    Comment by amit — April 23, 2008 @ 7:20 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.