Re: [nsbasic-ce] DECLARE vs Byte arrays

2010-01-29 Thread George Henne
The core problem here is that VBScript (the underlying engine) does not
support byte arrays.

I don't have a solution for you, but here is a related trick to get a
long from a byte array, using the newObjects SFMain object. It also
deals with the big endian/little endian problem, which you probably
won't have.

AddObject NewObjects.utilctls.StringUtilities,su
AddObject newObjects.utilctls.SFMain,FS
Set file=FS.OpenFile(DataFile)
...

Function getLong(offset)
Dim y
file.pos=offset
y=file.readbin(4)
y=su.BinToHex(y) 'convert the byte array into a format we can use
y=Right(  y,8) 'left pad it to 8 characters long
getlong=CLng(h  Mid(y,7,2)  Mid(y,5,2)  Mid(y,3,2)  Mid(y,1,2))
'reverse the byte order
End Function


From the TechNote 26 description it appears that API calls can be made
passing parameters as in ByRef X As Byte() with no problem.  However
due to VBScript limitations what you pass in (and get back) are arrays
of Integer (or short i.e. VT_I2, signed 16-bit integers).

The issue I have is that I need to be able to write these out (for
example to disk) as a stream of Byte values.

I could easily use the newObjects SFMain object to create an SFStream
object and call its WriteBin method.  However SFStream expects a Variant
buffer parameter containing an array of subtype Byte (VT_UI1).

I can see that the array of Integer subtype has advantages in allowing
VBScript manipulation, but I now seem to have a mismatch between DECLARE
and SFStream.

So my question is:  Does anybody have a suggestion for resolving this
mismatch, or do I have something confused on my part?

- Bob





Yahoo! Groups Links




-- 
You received this message because you are subscribed to the Google Groups 
nsb-ce group.
To post to this group, send email to nsb...@googlegroups.com.
To unsubscribe from this group, send email to 
nsb-ce+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nsb-ce?hl=en.



[nsbasic-ce] DECLARE vs Byte arrays

2010-01-28 Thread michiman56
From the TechNote 26 description it appears that API calls can be made passing 
parameters as in ByRef X As Byte() with no problem.  However due to VBScript 
limitations what you pass in (and get back) are arrays of Integer (or short 
i.e. VT_I2, signed 16-bit integers).

The issue I have is that I need to be able to write these out (for example to 
disk) as a stream of Byte values.

I could easily use the newObjects SFMain object to create an SFStream object 
and call its WriteBin method.  However SFStream expects a Variant buffer 
parameter containing an array of subtype Byte (VT_UI1).

I can see that the array of Integer subtype has advantages in allowing VBScript 
manipulation, but I now seem to have a mismatch between DECLARE and SFStream.

So my question is:  Does anybody have a suggestion for resolving this mismatch, 
or do I have something confused on my part?

- Bob

-- 
You received this message because you are subscribed to the Google Groups 
nsb-ce group.
To post to this group, send email to nsb...@googlegroups.com.
To unsubscribe from this group, send email to 
nsb-ce+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nsb-ce?hl=en.