VB4 introduces the use of double-byte characters. Most of this is transparent
to the programmer and requires no special consideration. When calling API
functions or reading/writing to a file VB will handle the conversion for
you automatically.
However, there may be times when you want to force a condition that
goes against VB's will. For example, you might want to write Unicode to
a file, pass a Unicode string to a function, or receive a Unicode string
from a routine. In these cases you will have to use VB4's new Byte declaration.
A String Byte can vary between one or two bytes depending upon how it is
used. A Byte-byte is exactly that: one byte.
To convert a string variable into a byte array, use this code:
Redim MyByteArray(0 to len(MyString$)-1) as Byte
MyByteArray() = StrConv(MyString$, vbFromUniCode)
To convert a byte array to a string:
MyString$ = StrConv(BA(), vbUniCode)
Due to a bug or design limitation, VB4 does not allow you to convert
a string to a binary array that is part of a Type structure. For example:
TYPE MyByteType
Bytes( 0 to 255) as Byte
END TYPE
Dim MBA as MhByteType
MBA.Bytes() = StrConv(MyString$, vbFromUniCode)
returns an error. However,
MyString$ = StrConv(MBA.Bytes() , vbUniCode)
works as expected.