You didn't mention what you need this for, but
you can do anything binary with Textstream. You
don't need ADODB and in many cases you
don't need conversion to bytes. A Textstream string
is binary until you look at it (quantum Textstream?).
Since VBS uses Chr(0) to demarcate string ends,
if you try to get the length of the string you'll get
the offset of the first Chr(0). If you try to use ReadAll
you'll only read up to the first Chr(0). Aside from those
limitations, you can read and write binary as Textstrream
strings.
If you use:
A1 = Array(1, 0, 100, 200, 255, 10)
you'll get a variant array. But those values can
be written to a string:
For i = 0 to UBound(A1)
s = s & Chr(A1(i))
Next
....and the string can be written to disk as binary.
For an example that reads and writes binary, also
using arrays to set up binary data, see here:
http://www.jsware.net/jsware/jsware/scripts.html#iconextr
It's a script that uses only Textstream to read from
any PE file that contains icons. It parses the resource
table, extracts the icon bytes, writes binary file headers
for each icon by using the array method above, then writes the
icons to disk. It may seem a bit sloppy to use Textstream for
that but it works, and on my Win98 1660 Athlon it extracts
and writes 350-odd icons from Shell32.dll almost instantly.
(It also avoids the version limitation associated with using
ADODB if the target computer doesn't have the version
with the Stream object - 2.6+, I think.)
--
--
Post by Arno BoschHi Richard,
I tried Michaels example code and had good results for chr(i) where
0<=i<=127 but it did not work for 128<=i<=255 at all.
You have to change the line "Stream.Charset = "ASCII"" to "Stream.Charset =
"windows-1252"" for making it work for 0<=i<=255.
So this code should work for my problem even though it is a detour when I
first have to create a file and then can import it as a byte-array.
Anyway I get the correct data-type (8209=array of byte). Thats what I wanted!
Thanks a lot to both of you for your help!
Arno