I need to convert a simple string in a Byte array using excel VBA. Then this byte array is used as the request's body.
How can I do that?
Thanks.
I need to convert a simple string in a Byte array using excel VBA. Then this byte array is used as the request's body.
How can I do that?
Thanks.
If you only need ANSI characters, you can use the StrConv() function as is done here.
Matthew answered how to convert to ANSI, but if you wanted the resulting byte array to still represent the original Unicode string, you'd simply assign it directly:
Public Sub Main()
Dim b() As Byte
Dim s As String
s = "Whatever"
b = s 'Assign Unicode string to bytes.'
s = b 'Works in reverse, too!'
Debug.Print s
End Sub
That's all there is to it. You end up with a 16-element Byte array, each successive pair describing one Unicode character.