An implementation of Visual Basic that is built into Microsoft products.
ADODB.Stream.Read(1) returns a Variant containing a SAFEARRAY of bytes, not a native VBScript array. Although IsArray(), TypeName(), and LBound() correctly identify it as a byte array, VBScript cannot directly index certain COM-returned byte arrays, resulting in a Type mismatch when you access buf(0).
This is a limitation of VBScript's interaction with COM automation objects rather than a bug in ADODB.Stream itself. VBScript handles normal arrays and COM SAFEARRAYs differently, and byte arrays are one of the edge cases.
As a workaround, try using AscB() on a one-byte binary string instead of indexing the byte array, or to read larger blocks and process them through another COM object (such as Scripting.FileSystemObject or a custom COM component). If you only need one byte at a time, another option is to use MidB()/AscB() on binary data after converting it appropriately.
If you must use ADODB.Stream, reading larger chunks and processing them outside of direct buf(0) indexing is generally the most reliable approach.
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin