devxlogo

Understanding Unicode

Understanding Unicode

VB4 introduces the use of double-byte characters. Most of this is transparentto the programmer and requires no special consideration. When calling APIfunctions or reading/writing to a file VB will handle the conversion foryou automatically. However, there may be times when you want to force a condition thatgoes against VB’s will. For example, you might want to write Unicode toa file, pass a Unicode string to a function, or receive a Unicode stringfrom 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 isused. 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 ByteMyByteArray() = 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 converta string to a binary array that is part of a Type structure. For example:

 TYPE MyByteType	Bytes( 0 to 255) as ByteEND TYPEDim MBA as MhByteTypeMBA.Bytes() = StrConv(MyString$, vbFromUniCode) 

returns an error. However,

 MyString$ = StrConv(MBA.Bytes() , vbUniCode) 

works as expected.

See also  5 Benefits of Using Time Tracking Software
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist