Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 688

How do I use the byte arrays returned from Read method of the ADODB.Stream object?

$
0
0
The only way in VBScript to read data properly from a binary file is the ADODB.Stream object. Here's some code I have to read a file in the VBScript code of my ASP page.
Code:

        dim obj
        dim bytearray
        dim n
        set obj=createobject("adodb.stream")
        obj.type=1
        obj.open
        obj.loadfromfile "mydata.dat"
        bytearray = obj.read
        obj.close
                       
        for n=0 to 9
                response.write(bytearray(n))
                response.write(vbcrlf & "<br />")
        next

It reads a file called mydata.dat and attempts to output the text representation of the numerical values of the first 10 bytes of the byte array. But unlike other arrays, byte arrays don't seem to be able to be accessed like bytearray(n). Unlike in VB6, in VBScript the byte arrays very strongly resist being accessed in any way other than in bulk. I can pass the entire array variable around, but as soon as I attempt to access any of the bytes in that array, it suddenly gives me an error.

What is the proper way to access the bytes of a byte array in VBScript?

Viewing all articles
Browse latest Browse all 688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>