Probleme with Importing Binary file

I’m trying to import a binary file from another system into Navision. but there Decimal are really double which are 8 bytes long. but in Navision, has you all know, they are 12 bytes long. So each time I do a read with a decimal variable, it reads 12 bytes. But I only want to read 8 bytes.(cuz after that it is something else) plus, you cann’t specify any range in the READ function Anyhelp would really be really appreciated. tx

how are you going to convert the binary into c/side decimals? I suggest you write an ocx to do the job.

THAT’s my problem! cuz text and integer variable are converted auto. and decimal too, except in my case which are 8 bytes long(because the other system WRITES them in that way). so when I read them, I read 12 bytes (8 bytes{the decimal I NEED} +4 bytes {of garbage}) hope this help. I though as much, but I was wondering if there was a “simple” solution do this.

Are you using FILE.TEXTMODE(FALSE) ?

of course [;)]


Originally posted by mleblanc
of course [;)]

We’ll not tell anybody! [:D]

here’s what I got so far: Filename.OPEN(‘MyfileName.txt’); Filename.TEXTMODE(FALSE);//to tell Nv it is in Binary Filename.READ(Integer);//everything is ok, because the system is reading 4 bytes and Int are 4 bytes Filename.READ(Decimal);//here the system is reading 12 bytes but my file is formatted as 8 bytes for double. but since double are NOT into Navision I must use the next best thing => decimal with 12 bytes. is it clearer?

Yes, this helps! You could read chars instead like this: FOR i = 1 to 8 do Filename.READ(Char[i]); and then convert the array of chars to decimal manually.

much clearer. If you want to keep it in Navision, then Preben’s solution is the one, but I don’t see how you will convert the chars into decimals. I think you are going to need an external solution. btw where is the data coming from?

Alternatively read(Bin) where Bin is a Binary(8) variable. Whether you read it into an array or into a Binary you’re still left with the same problem: converting the array/binary to decimal. A solution might be to write the variable to another file (binarily of course) and then read from this file into the decimal variable - don’t know if this would work, though.

[quoteA solution might be to write the variable to another file (binarily of course) and then read from this file into the decimal variable - don’t know if this would work, though.

I don’t think this will work, since you cant just add 4 bytes to an 6 byte decimal, and expect it to be compatible with a 12 byte. The issue really comes down to converting an 8 byte decimal to a 12 byte decimal.

You really can’t convert data types this way. Do you know the binary layout of the 8-byte decimal you are trying to read and the layout of the Navision decimal? Probably not - the Navision decimal uses BCD which is unlikely to have any resemblence to your decimal binary; just as it has no resemblence to the double value, which is floating point. You need to go through APIs to do this stuff where type conversions are handled correctly.

I agree with Robert Single (4 bytes) & double (8 bytes) floating values use floating binary format which code a sign, an exponent and a mantissa according to IEEE standards or else. For example IEEE double format : Byte8 Byte7 Byte6 … seeeeeee eeeemmmm mmmmmmmm mmmmmmmm … s = sign bit e = exponent bit m = mantissa bit I think it’s very difficult to write a routine to decode binary floating value because you need to use binary operators like ‘And’ ‘or’ that doesn’t exist in C/Side. Secondly, you must handle numeric overlimit on very high and low values. Best regards

I try to write a function to decode for MBF format (the same using IEEE format is impossible) // MBF (Microsoft Binary Format) // byte8 byte7 … // eeeeeeee smmmmmmm mmmmmmmm … - BinVal[] array[ 8] of char - Exponent,Mantissa,sign locals decimal - i local integer Exponent := BinVal[ 8] ; Exponent := (Exponent - 128) - 56; Exponent := POWER(2, Exponent); // Overflow is not check IF BinVal[7] >= 128 THEN BEGIN Mantissa := BinVal[7]; Sign := -1 END ELSE BEGIN Mantissa := BinVal[7] + 128; // Lucky guy! OR operator is not necessary Sign := 1; END; FOR I := 6 DOWNTO 1 DO Mantissa := (256 * Mantissa) + BinVal[i]; // Overflow is not check EXIT(Sign * Exponent * Mantissa); // Overflow is not check I don’t verify it. It’s just for sample. You can also search “Understand IEEE Floating-Point” on Microsoft Knowledge base, to have more information

Thank you guys for the responses, but unfortunatly none of them worked. Patrick you solution came close but no cigar. I think I’ll do an external program.[V] David, the data is from an app. called Axys from Advent inc. Thank you all![:D]