Jalaj P. Jha Technical & Miscellaneous Ramblings

23Jan/0744




VB Forms in Hindi Unicode Fonts

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
Comments (44) Trackbacks (4)
  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

  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

  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.

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

  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

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

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

  8. 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

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

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

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

  12. 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

  13. 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

  14. 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.

  15. 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

  16. 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

  17. @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 …

  18. 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

  19. 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/

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

  21. How can we use unicode texts using resource file

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

    Thanks in Advance.

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

  24. 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..

  25. i had a list of names in excel typed in english i want to convert its script language to hindi. please help how to get it done in vb or any other way u can suggest.

  26. i have some data in urdu in database (msaccess). i m using ADO in vb to access my data in vb form plz help me

    Regards

  27. hello sir

    thanks for your suggestion on different topic on unicode. I am student of mca and first time i am doing a project which have hindi font and i faced lots of problem. After searching i google i fallowed ur blogs .And there are very good related to this topic .Hope so u will send me replay

    thanks

  28. hello,
    Thank you for your information. That is very useful to me. I have another problem. I used components of Microsoft Forms 2.0 object library to display unicode data. I want to define new index for combo box because I want to display only City Name with combo box and City Code save as that index. What should I do?….. ordinary combo box(not unicode combo box) is ok for that with following code……
    cbo.AddItem “CityName”
    cbo.ItemData(cbo.NewIndex) = “CityCode”

    if I want to get that new index,
    cbo.ItemData(cbo.ListIndex)

    if I want to use that logic in unicode combo box, ??????????????????????. Please suggest me……

    thanks

  29. Hi we are trying the same example but we are not able to see the devanagari script. instead we are getting the ???? marks

  30. Here is an equivalent:

    Function get_unicode(file As String) As String
    Dim file_id As Long
    Dim cont() As Byte
    file_id = FreeFile()
    Open file For Binary As file_id
    ReDim cont(LOF(file_id))
    Get file_id, , cont()
    get_unicode = cont()
    Close file_id
    End Function

  31. dear sir,
    please give me info. that how we change windows default font to marathi(ex.dv-ttganesh).

  32. is there any alternative way to use unicode in visual baisc menus?

    actually when i want to add unicode strings into menu captions it changes then into question marks.

    please tell me if you know. I shall be very thank full to you.

  33. How to create string table in hindi? And load those string from string table at runtime? My application is in MFC…So is it possible to create string table in hindi in MFC?

  34. Hi, it’s very useful information…Thanks.

    But how to write text in Hindi in the textfile(.txt)

    I also want to create the same for Gujarati.

    How to write in textfile in Hindi & Gujarati with “Arial Unicode MS” Font.

    I am waiting for ur early rely!!!

  35. हैलो सर

    श्रीमान जी मैं VB6 में हिन्दी फोन्ट मंगल (Script Font) का इस्तेमाल करना चाहता हूं। किन्तु वहां पर केवल ????????? ही आते है।

    कृपया इस समस्या का हल भेजे।

    धन्यवाद।

    रिम्पु सिंगला

  36. कृपया उपरोक्त प्रोजेक्ट का कोड भेजे।

    क्योंकि Arial Unicode MS में हमें Dev… नहीं मिला।

    और केवल ?????????? ही आ रहे है।

  37. Thank you very much for information.

  38. 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.

  39. you hv not notes in hivdi

  40. 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…

  41. How do i put unicode fonts i.e Gujarati fonts on MSFlexGrid????

  42. धन्यवाद, मुझे यूनीकोड हिन्दी मे फ़ोर्म बनाने मे मदद मिली। पर मेनू आइट्म और फ़ोर्म का नाम हिन्दी मे केसे लिखे?

  43. the information is very useful for me as i am trying to build a text editor in hindi language using vb6. the problem is i am unable to change the language of menu items . i am not getting the way to do that. please provide me some suggestion if possible

  44. hie..!

    tanQ verymuch for dis information..!

    can we get “Arial Unicode MS” for free..!!

    ver shall i get it..??

    plz help me..!

    regards
    sAn.!


Leave a comment