Longer Answer:
VBA strings are all unicode deep beneath the surface of the IDE, but they are always presented to the VBA programmer as pure ASCII strings
Summary
You cannot directly insert or extract Unicode from VBA strings. The normal workaround is to use a byte array or to treat the string as a byte buffer
The way to use hexadecimal literals is to prefix them with &H (rather than 0x). They will not however be coerced to characters in the way you are trying, so, in your example, if you coded: [tt] Private Const Space As String = &H3000[/tt]
.. although it would compile, the string would have the value "12389".
There is no mechanism for entering non-ANSI characters directly in the editor, and the way to get them into strings is to use the [blue][tt]ChrW[/tt][/blue] function, but functions cannot be used outside procedures, nor can they be used in the declaration of Constants. So, in this instance, you must use a variable, rather than a constant, and you must initialise it in a procedure.
I must disagree with Mike. All VBA Strings are Unicode strings, not deep within, but everywhere. There is some conversion goes on behind the scenes when interfacing with external code, but at that point they are no longer VBA strings; within VBA you always have wide characters. If you explicitly use ANSI characters you will get unexpected results - about the only place you come across this is with the [blue][tt]Chr[/tt][/blue] and [blue][tt]Asc[/tt][/blue] functions.
Enjoy,
Tony
------------------------------------------------------------------------------------ We want to help you; help us to do it by reading this:Before you ask a question.
> They are BSTRs, which are not quite the same thing
That is a technicality - and that is beneath the surface. Because VBA (and, more generally, Typed languages) isolate the programmer from memory, it is necessary for control information about variables to be maintained. All that a BSTR is, is a unicode string plus that control information.
All normal interactions with strings in VBA are with unicode characters, and none are with ANSI (or ASCII) characters, and you most certainly can insert and extract unicode characters to and from VBA strings, without messing about with byte arrays.
Enjoy,
Tony
------------------------------------------------------------------------------------ We want to help you; help us to do it by reading this:Before you ask a question.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.