Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 196
Default Question on Unicode and string conversions in VBA

Given the following two code snippets, how come I get different output?


Code:
Sub test()
Dim str As String
Dim b() As Byte
str = "hello"
b() = str
str = ""
For i = LBound(b) To UBound(b)
str = str & b(i) & " "
Next i
Debug.Print str
End Sub


The above produces the following output:

Code:
104 0 101 0 108 0 108 0 111 0


second procedu

Code:
Sub test2()
Dim str As String
Dim b() As Byte
str = "hello"
b() = StrConv(str, vbUnicode)
str = ""
For i = LBound(b) To UBound(b)
str = str & b(i) & " "
Next i
Debug.Print str
End Sub


Which produces this output:

Code:
104 0 0 0 101 0 0 0 108 0 0 0 108 0 0 0 111 0 0 0


My question is: why the additional zeroes from the second procedure?
Assigning a string to a byte array fills the byte array with the
unicode characters, and I thought this was essentially what the StrConv
function did (with vbUnicode option).

Can anyone settle my curiosity?

Thanks for any/all replies!

Best regards

Richard

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
conversions dperalta Excel Worksheet Functions 1 July 18th 08 10:17 PM
Conversions dengel Excel Worksheet Functions 2 February 13th 07 09:56 PM
simple unicode question Gary''s Student Excel Discussion (Misc queries) 8 April 16th 06 02:34 AM
How to show unicode String ? Nick Excel Programming 2 August 24th 04 12:03 PM
Unicode string parsing? Please help! Douglas Gennetten[_2_] Excel Programming 1 January 16th 04 08:31 AM


All times are GMT +1. The time now is 07:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"