Jalaj P. Jha

Technical & Miscellaneous Ramblings

VB Forms in Hindi Unicode Fonts

with 48 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 23rd, 2007 at 5:14 am

48 Responses to 'VB Forms in Hindi Unicode Fonts'

Subscribe to comments with RSS or TrackBack to 'VB Forms in Hindi Unicode Fonts'.

  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

    Amit Pandey

    3 Apr 07 at 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

    phil

    4 Apr 07 at 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.

    Jalaj

    5 Apr 07 at 4:03 am

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

    phil

    9 Apr 07 at 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

    Amit Pandey

    11 Apr 07 at 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 [...]

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

    Jalaj

    12 Apr 07 at 11:35 am

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

    Shrikant Agrawal

    15 Apr 07 at 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

    Dinal

    9 May 07 at 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 [...]

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

    Bharat Patil

    6 Jul 07 at 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.

    Makrand

    30 Jul 07 at 11:42 am

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

    Les

    7 Sep 07 at 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

    Pankaj

    1 Nov 07 at 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

    Pankaj

    1 Nov 07 at 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.

    Jalaj

    1 Nov 07 at 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

    Pankaj Kumar

    7 Nov 07 at 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

    Pankaj

    8 Nov 07 at 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 …

    Jalaj

    14 Nov 07 at 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

    Jamal Ahmad

    27 Nov 07 at 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/

    Jalaj

    28 Nov 07 at 1:55 pm

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

  23. How can we use unicode texts using resource file

    Balaji

    2 Feb 08 at 7:39 am

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

    Thanks in Advance.

    Balaji

    2 Feb 08 at 7:40 am

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

    amit mittal

    19 Mar 08 at 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..

    amit

    23 Apr 08 at 7:20 am

  27. soma…

    soma

    7 Jun 08 at 11:01 am

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

    zaki

    12 Jun 08 at 8:09 am

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

    Khalid

    24 Jun 08 at 9:21 am

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

    nitesh

    25 Jun 08 at 6:08 pm

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

    EI EI

    6 Aug 08 at 6:04 am

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

    Vivek

    8 Aug 08 at 11:19 am

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

    MarioRR

    22 Aug 08 at 4:01 pm

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

    pankhade nivrutti

    24 Aug 08 at 12:16 pm

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

    Sumra

    19 Sep 08 at 4:26 am

  36. 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?

    Apurv

    15 Oct 08 at 12:18 pm

  37. 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!!!

    Apurv

    17 Oct 08 at 10:49 am

  38. हैलो सर

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

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

    धन्यवाद।

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

    Rimpu

    27 Oct 08 at 9:22 am

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

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

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

    Rimpu

    27 Oct 08 at 9:33 am

  40. [...] VB Forms in Hindi Unicode Fonts [...]

  41. Thank you very much for information.

    Shailesh

    29 Dec 08 at 9:00 am

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

    29 Dec 08 at 9:25 am

  43. you hv not notes in hivdi

    divya

    29 Mar 09 at 9:45 am

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

    28 Apr 09 at 1:16 pm

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

    Punit

    7 Jul 09 at 5:05 pm

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

    durwesh

    7 Nov 09 at 4:27 am

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

    fatima

    4 Dec 09 at 3:31 am

  48. hie..!

    tanQ verymuch for dis information..!

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

    ver shall i get it..??

    plz help me..!

    regards
    sAn.!

    Santhosh

    17 Dec 09 at 6:19 pm

Leave a Reply