-
July 10th, 2008, 10:08 AM
#1
How to convert Variant to Byte Array?
Is there a way (beside doing it in a loop value by value) to convert a variant, which contain an array of byte data, to a byte array?
-
July 10th, 2008, 02:34 PM
#2
Re: How to convert Variant to Byte Array?
Yes. Declare a dynamic Byte array, and use StrConv().
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
July 10th, 2008, 11:58 PM
#3
Re: How to convert Variant to Byte Array?
Code:
Dim b, a() As Byte, aa() As Byte
ReDim aa(2) ' Source byte array
aa(0) = 11
aa(1) = 2
b = aa ' Store byte array into variant
a = b ' Store variant with byte array into byte array
With best wishes,
Vita
-----------------------
Russian Software Development Network -- http://www.rsdn.ru
-
July 11th, 2008, 12:46 AM
#4
Re: How to convert Variant to Byte Array?
Thank you both for reply!
WizBang, my data is not a string. All values for strconvs' 'conversion' argument seems to change the content of the byte array - right?
Vi2, using an 'undimed' dynamic array does it :-) (unfortunately I tried with a 'dimed' one before)
-
July 11th, 2008, 08:33 AM
#5
Re: How to convert Variant to Byte Array?
You can use StrConv() to accomplish your goal, but I'm not sure what you mean by "change the content of the byte array". It can fill the Byte array with the contents of the Variant, but the the array must not be ReDim'd first.
Obviously the method posted by Vi2 can work, though I seem to recall certain cases where I needed to use StrConv(). Off hand I don't recall the specifics, so I can't say whether it has any bearing on your particular need. I never use Variants (too slow), so perhaps that's what the difference was.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|