View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Arnaud[_2_] Arnaud[_2_] is offline
external usenet poster
 
Posts: 1
Default read a Unix binary file


"sali" a écrit dans le message de news:
...
"Arnaud Boëlle" wrote in message
...
Hi,

I need to read unix binary files with Excel VBA.

The problem is not to read a binary file. I use :

Dim buffer(1 to 1000) as single
Open file For Binary As 1
Get #1, 1, buffer

The problem is that IEEE binary information are stored left-to-right in

UNIX
and right-to-left in WINDOWS
(or the contrary).

I found a first solution to this problem which is

read binary data in a buffer of byte
invert 4 by 4 the bytes of buffer
write buffer in a new binary file
read binary data

Does anyone know a better solution ?


i usualy do a in_memory_swap.

if i need to read long_int, read for bytes from file,
than, in reverse order create character (hex) representation
and let clng() function make number, or
simply multiplying read bytes like:
byte1*256^3+byte2*256^2+byte3*256+byte4



I understand the second solution you propose :
byte1*256^3+byte2*256^2+byte3*256+byte4.
How to do the same for Single ?

I don't understand the first one. How to make a character (hex)
representation ?
I've tried :

dim buffer (1 to 4) as byte
dim x as single
get #1,,buffer
x=csng(buffer) <-------- refused by the compiler !

Thank you for your help,