how can i use Unicode in Visual basic 6.0 plz tell me an example

plz tell me how can i use unicode in vb 6.0
ibrarsahelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yronnenCommented:
VB6 store strings internally as unicode. You do not have to do anything.

If you have an ANSI string that you want to convert to unicode, you can do it this way:
dim m() as byte
m=strconvert("hello",vbUnicode)

for more info check msdn for "StrConv Function"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yronnenCommented:
Actually, the demo code will not work, since the "hello" string is already unicode. If you load text from a database or a file and this text is ANSI, you can use the function strconv.
0
VBtomCommented:
Hi

It's true that VB6 stores string as unicode.
You use AscW$() for getting a unicode number of a character, and ChrW$() for producing a unicode character (if you cannot type it: the VB editor works in ANSI).
For example, if you want that a string contains "Athína" in Greek characters, you say:
MyStringVariable =  ChrW$(913) & ChrW$(952) & ChrW$(942) & ChrW$(957) & ChrW$(945)

Asc$() and chr$ are for ANSI (0..255).

If you have ANSI text, e.g. from a text file or an access97 database, you could use StrConv to convert it, but it's done automatically when you assign it to a string variable.

So working with unicode in VB is no problem.

But the big problem is displaying unicode characters when they're not in the standard ANSI set:
VB controls like textboxes only show ANSI-characters (0..255) - (I'm not sure,  might be DBCS as well, but that counts for the same)
When you assign a string to the .Text or .Caption of a VB control, all unicode information gets lost and unicode characters are converted to ANSI characters using the default codepage of the OS.
This means e.g. that accents get lost, you get another character or you see a square.

For displaying other charcters, you need a special font that has the desired characters in the 0..255 charset.
If you don't have such font, it should be easy to find a free font on the internet that can do see.
But 2 problems remain:
-if you want to display for instance both west-european characters in the standard ANSI set (like é ñ ü), polish characters and greek characters, you need 3 different fonts (a standard ansi font, a special CE font and a special Greek font).
-as far as I found out, there seems no way to convert unicode to another than the standard charset (may be there exists some api function for that). This means that the automatic conversion does not work for displaying the characters even if you use an appropriate font.
I once had to display polish characters from an excel file (unicode) in a vb textbox and the other way. The way I solved it, was:
-I found out the numbers of the special characters in unicode (Word is useful for that),  and the numbers in a special font for them.
-then I made two functions UnicodeToCE and CEToUnicode: these examine the numbers of all characters in the string; if it's one of the special charcters, it's replaced by the right one.
For example, the polish "l" with a line through is unicode nr. 322 and  has number 179 in a special CE font,  so depending on the direction chrw$(322) is changed to chr$(179), or the other way.
-Then I passed all text that had to go from excel to the textbox or the other way through my functions.

Maybe not elegant but it worked and I don't know if there's a better solution.

Hope this helps you.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

VBtomCommented:
I forgot to say some important things about unicode and vb6:

-Whether you'll have problems depends of the languages used: the standard ansi charset contains all special characters needed for westeuropean languages: Scandinavian languages, German, Dutch, French, Spanish, Portuguese and Italian. So you won't have problems with these at all.

-You can use AscW() /ChrW() without $ as well, it doesn't always work with $

-There IS one control in VB6 that can display unicode charcters correctly: a richtextbox with the font set to Arial Unicode MS. It can receive unicode characters correctly through copy and paste or OLE-drag and drop.
However, it's not possible to get the unicode number of a character in the .Text of it: you'll always get 0..255 numbers (this makes me suspect that it should be possible to get the 0..255 numbers in special fonts of unicode characters through some api-function). Neither is it possible to add a unicode string  composed with chrw() to it correcty by saying RichTextbox1.Text = Richtextbox1.Text & MyUnicodeString. I don't know how you can without using clipboard or oledata.

Note: if you need to find out unicode and 0..255 numbers of certain characters, post a comment, then i can explain you how.

0
danaseamanCommented:
The easiest way to use Unicode with Vb is to use the Unicode aware controls from FM20.Dll(Forms 2.0 Object Library). This DLL is part of MS Office and is non-redistributable but you can download it free from MS as part of SetupPad.Exe.
http://download.microsoft.com/download/activexcontrolpad/Install/4.0.0.950/WIN98MeXP/EN-US/setuppad.exe

Put a Forms 2.0 Textbox control on your form and test it with this code:

Private Sub Form_Load()
   TextBox1 = "Chinese" & StrConv("ÿþsS`Oegُ?Q„vîv„v", vbFromUnicode)
End Sub

You can also copy Unicode from Offce and other apps into the clipboard and paste them into this TextBox.
0
VBtomCommented:
Hi danaseaman,

I know that the "userform"-textboxes (like in Word en Excel) can display unicode text without problem.
But I have 2 questions about that:
*what about the distribution rights if you make a VB app that uses that?
*how can I put such a textbox on a VB form without getting system error &H80070485?
0
danaseamanCommented:
Since you can't distribute FM20.Dll with your package the user must have MSOffice installed. If the user doesn't have Office installed then he/she can download and install the free SetupPad.Exe from MS at the link in my previous post.

Unable to put  textbox on a VB form without getting system error &H80070485...
Go to this link for info on system error. I found that FMENU20.Dll  must also be present on your system or VB will not let you put the textbox on a VB form! This occurs on non-English Office installations. SetupPad.Exe should include this extra DLL.
http://www.cyberactivex.com/requirements.htm 

If you are using 2000/XP and it was installed with FarEast(Asia) support you should see the Unicode in the Textbox. You can add FarEast(Asia) support via the control panel. On 98/ME makes sure you have a Unicode Font installed such as Arial Unicode and set the TextBox to that Font.

I'm looking for a Unicode aware textbox(free) so that I don't need the extra dependency. The alternative is to write an all API TextBox yourself with Unicode support using CreatWindowExW.

Screenshots of a working Unicode aware project can be seen on my site at:
http://www.cyberactivex.com/
Click on "Coming Soon"
0
danaseamanCommented:
0
VBtomCommented:
danaseaman,
thank you very much for the anwers to my questions about your suggestion.
I have a dutch office and fmenu20.dll was missing indeed.
btw, a useful article about writing/reading unicode in textboxes using api's is http://www.fawcette.com/Archives/premier/mgznarch/vbpj/1999/08aug99/bb0899.pdf

0
danaseamanCommented:
I've read that article before. It suggests using Windowless controls as an alternative to work with Unicode but I can't get it to work (I still get "??????" in lieu of Unicode) using XPPro/Sp1. If I find a free alternative other than  FM20.Dll(Forms 2.0 Object Library) I will post it here.
0
leonstrykerCommented:
I needed to place some Greek text in regular labels  This is the function i used to do so:

Function ConvText(lblLabel As Object, strString As String, strLang As String, _
                        Optional blnBold As Boolean = False, _
                        Optional intFontSize As Integer = 8) As Boolean
'------------------------------------------------------------------------------
'Procedure Name: ConvText
'       Purpose: Converts Unicode text so it can be displayed in a label
'    Parameters: lblLabel       -   Label used to display the text
'                strString      -   Text to be converted
'                strLang        -   Language to be converted
'                blnBold        -   Optional font setting to bold
'                intFontSize    -   Optional font setting size
'------------------------------------------------------------------------------
Dim strSQL As String, rsRecSet As ADODB.Recordset
Dim arrUnicode() As Byte, intCharSet As Integer, strFont As String, intLen As Integer
Dim intIndex As Long

    ConvText = True
    On Error GoTo ERROR_FUNCTION
'    '/ Open connection to Oracle DB
'    If Not OpenConnOracle(cnConn) Then Exit Function
    '/ Get language specific information
    strSQL = "SELECT * FROM Lang WHERE TLANGDSC = '" & UCase(strLang) & "'"
    If Not OpenRecSet(strSQL, cnConn, rsRecSet) Then Exit Function
    If Not rsRecSet.EOF Then
        intCharSet = rsRecSet("nCharSet")
        If intCharSet = 0 Then
            GoTo EXIT_FUNCTION:
        End If
        strFont = rsRecSet("tFont")
        '/ Close language specific record set
        CloseRecSet rsRecSet
    Else
        GoTo ERROR_FUNCTION
    End If
    '/ Parse string into byte array
    arrUnicode() = strString
    intLen = Len(strString)
    '/ Set label settings
    With lblLabel
        .Caption = ""
        .Font.Bold = blnBold
        .Font.Name = strFont
        .Font.Size = intFontSize
        .Font.Charset = intCharSet      '/ 161 for Greek
    End With
    '/ Convert by character, skip every other one for unicode characters, but not standard ones
    For intIndex = 0 To intLen * 2 - 1
        If ((intIndex + 1) Mod 2) <> 0 Then
            Select Case arrUnicode(intIndex)
                Case Is < 128                   '/ English text
                    lblLabel.Caption = lblLabel.Caption & Chr$(arrUnicode(intIndex))
                Case Else
                    '/ Other hex numbers may be needed for other languages &H30 works for Greek
                    lblLabel.Caption = lblLabel.Caption & Chr$(arrUnicode(intIndex) + &H30) & ""
            End Select
        End If
    Next intIndex
EXIT_FUNCTION:
    DoEvents
    Exit Function
ERROR_FUNCTION:
    Debug.Print Err.Number & " : " & Err.Description
    ConvText = False
    GoTo EXIT_FUNCTION
End Function
0
CleanupPingCommented:
ibrarsahel:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
leonstrykerCommented:
It is very hard to recomend anything then the original question is so general.  I think it should probably be deleted.
0
Alex HalesCommented:
If you got the problem with the Unicode in Visual Basic 6 for the Hp system the settings required that can get from the https://hpsupports.co/.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.