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.
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?
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 />")
nextWhat is the proper way to access the bytes of a byte array in VBScript?