> 
> I'm pretty impressed with fileIO being able to do this stuff. When I get
> my code working I will be happy to share it. I have a parent script
> wrapper for fileIO featuring handlers like 'readByte()' 'readCstring()'
> and (coming soon with your help) 'readShort()' and 'readLong()'.
> 
> Brennan 

I also looked into this a while ago & also have an incomplete parent wrapper
for fileio calls.  The fun really starts when you want signed integers, and
don't even mention floats.  IIRC I got most of it working, but ended up not
needing it in the project.  If I needed it again I think I would find some
$$ for BinaryIO.

Try these handlers on for size - not sure if they are completely optimised.

johnAq



property pFileio  --fileiio object
property pByteSwap  --flag variable to indicate byte swapping


on readShort me
  --Returns a 2 byte value from file interpreted as
  --a two-byte integer
  if pByteSwap then
    char1 = pFileio.readChar()
    char2 = pFileio.readChar()
  else
    char2 = pFileio.readChar()
    char1 = pFileio.readChar()
  end if
  char1AsInt = charTonum(char1)
  char2AsInt = charTonum(char2)
  short = char2AsInt * 256 + char1AsInt
  return short
end



on readLong me
  --Returns a 4 byte value from file interpreted as
  --a four-byte integer
  if pByteSwap then
    char1 = pFileio.readChar()
    char2 = pFileio.readChar()
    char3 = pFileio.readChar()
    char4 = pFileio.readChar()
  else
    char4 = pFileio.readChar()
    char3 = pFileio.readChar()
    char2 = pFileio.readChar()
    char1 = pFileio.readChar()
  end if
  char1AsInt = charTonum(char1)
  char2AsInt = charTonum(char2)
  char3AsInt = charTonum(char3)
  char4AsInt = charTonum(char4)
  long = (char4AsInt * 16777216.0000)
  long = long + (char3AsInt * 65536)
  long = long + (char2AsInt * 256)
  long = long + char1AsInt
  if abs(long) < the maxInteger then long = integer(long)
  return long
end




[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL 
PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping 
with programming Lingo.  Thanks!]

Reply via email to