Variant to Byte Array, and back 
Author Message
 Variant to Byte Array, and back

Hi..

I need to convert a variant to a byte array....

In the Variant is an array... I need to convert the variant to a Byte Array,
send it to another program and then reconstruct the variant as it existed
previously.

So if this was possible in VB... Life would be good... (unfortunately Life
is NOT good)

Dim v as variant
Dim b() as Byte
Dim vNew as variant

v = Array("abc", "def", "geh")
b = v
..
..
vNew = b
..

vNew should have the same poperties as the original "v" variant variable...
(ie. embbeded array)

Any help appreciated...

Cheers



Tue, 03 Jun 2003 00:46:33 GMT  
 Variant to Byte Array, and back

Quote:
>I need to convert a variant to a byte array....

The easiest way to do it is to store it in a PropertyBag object.

Dim pb As PropertyBag
Set pb = New PropertyBag
...
pb.WriteProperty "MyVariant", v
b = pb.Contents
Set pb = Nothing

And then reverse the process in the recieving code.

The only problem is that it doesn't work on arrays like in the code
you posted. You'd have to iterate the array and save each element.

Matt

============================================

  CodeHound - Free VB Search Engine
  http://www.codehound.com



Tue, 03 Jun 2003 01:10:56 GMT  
 Variant to Byte Array, and back

Quote:
> The only problem is that it doesn't work on arrays like in the code
> you posted. You'd have to iterate the array and save each element.

For arrays look at the Custom PropertyBag sample on my page.

--
Eduardo A. Morcillo
http://www.domaindlx.com/e_morcillo



Tue, 03 Jun 2003 02:11:12 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Convert user defined type or variant to byte array (and back)

2. Variant to Byte Array, and back

3. Copying a long array into a byte array and back

4. Copying a long array into a byte array and back

5. Copying a long array into a byte array and back

6. Copying a long array into a byte array and back

7. Copying a long array into a byte array and back

8. Array to Variant and Variant to array problem

9. Passing variant containing byte array

10. Variant (array of bytes)

11. Converting a Variant To an array of bytes!

12. Move data from a variant to byte array

 

 
Powered by phpBB® Forum Software