Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA how to cope with unicode string

Status
Not open for further replies.

brusi

Programmer
Jan 25, 2006
3
GB
Hi,
I've done an example of what I meet when I try to pass russian character to a string or to a message box.
I expect the message box contains "abcde" in cyrilic alphabet but the result of that are just funcy characters instead.
Any help?
I also changed the regional and language system setting but nothing changed.
Many Thanks
*********************************
cells (1,1) is = to "abcde" in cyrilic alphabet

Sub test()

Dim strRuss2 As Variant
Dim strRuss3 As String

strRuss3 = Cells(1, 1)
strRuss2 = "2ôèñâó" ' these should be "abcde" in cyrilic

MsgBox "Code = " + "1ôèñâó" + " " + strRuss2 + " " + strRuss3 + " " + Cells(1, 1)

End Sub
 
Hi brusi,

I think you may be running into restrictions of MsgBox which calls the system MessageBoxA routine.

An API call to MessageBoxW ought to be possible. All strings in VBA are unicode and are converted behind the scenes. There are techniques to work around this but I can't recall them off the top of my head - I will see if I can sort something out.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Many Thanks

the message box output is only one of the way I should handle data.
I noticed that if I set to russian the language for non-unicode programes it works.
One russian client also told me that with his PC configuration (Russian version of Microsoft Office) it worked without problem.

May be it depends by the system settings.
Thanks again.

 
I'm nowhere near an expert on this stuff - and don't have any kind of foreign installation on which to be able to test.

More or less all characters have a unicode code point somewhere which can usually be explicitly displayed if an appropriate font is installed on the computer. But there is another aspect to using characters in non-English alphabets.

Very loosely, characters can be grouped into three ...

(a) The original ASCII characters - codes 0 -127
(b) The 'extended ASCII' characters - codes 128 - 255
(c) All the rest

The same characters - including the english alphabet - are always in (a) and are available on all systems, and easily usable with all software.

The characters in (b) depend on what is called the local code page - and should include local alphabetic characters (hence Cyrillic in Russia - but I haven't checked). The code page is set within Windows I think but I don't really know much about it. Again these characters are easily usable with all software but may require explicit regional coding.

The characters in (c) are what are usually called unicode characters - and do technically include (a) and (b). They are the same everywhere (except for those in the local code page) but special coding techniques are sometimes needed to make full use of them and, as already said, appropriate fonts are, of course, needed.

Without knowing more of how you are working and in what environments you want your solutions to work, it is hard to say much else. If you design a system to work with local data (input, perhaps, on a local keyboard or with a local IME) I wouldn't expect huge problems. But if you design something to work on a UK system (or wherever in the world you are) to explicitly use non-local characters you may find some oddities when the system is transported to a different locale.

Looking back at your original example of Cyrillic text in a cell - if this was entered on a sytem in a locale which uses the Cyrillic alphabet, the characters may well be in group (b) on the local code page, in which case 'normal' code will work well with them. On the other hand, trying to enter them in the UK, say, where they require special treatment may cause you problems.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Many Thanks Tony,

It was very exaustive and clear.

I solved my problem in this way.
The vba works already on UTF-8, the only problem was to write variable value into and UTF-8 compatible environement. So I start writing into a binary file using PUT instead of Print and the variable value keep thier real value even when they are printed elsewhere.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top