Question

I am trying to write a distributed application in Java, however the program I am writing is replacing a VB6 equivalent. The data files that are used are live files containing binary data written using VB6 put methods and are constantly in use by several applications.

I have successfully retrieved text from the file by reading an entire record (160 bytes) into the byte array buf. Then using the following line to extract text fields

new String(Arrays.copyOfRange(buf, 15, 40), "ISO-8859-1");

I also need to extract the VB6 data types Boolean, Double, Integer, Long and Single. Eventually I will probably need datetime as well but not for the first stage. To do doubles I know that the endianess is Little endian rather than big in VB6 so I have the following function

public static double toDouble(byte[] bytes) {
    return ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getDouble();
}

The first few data fields are strings then 2 double, the output at the moment is:

Barcode: 1            
Dept Code: 18
Description: MISC NON VAT             
Trade Price: 0.0
Retail Price: 0.009999999776482582

As you can see the first 3 are logical and match the content in the datafile. The trade price should be 0.0 so that is fine but retail price should be 0.01 which would be correct if I round it but, A. I am uncomfortable rounding price and vat info and B. I can't reasonably write any changes back to the file as if I am reading with a margin or error then I will probably be writing with the same margin of error. I also tried manually bit-shifting but for a double Java complains if I try and shift more than 31 bits which of course I need to in order to do 56.

Any help on this would be much appreciated

Was it helpful?

Solution

If I were trying to do this, I think I'd write a VB6StreamReader that encapsulates the reading of VB6 primitives and deals with the quirks in the data that result from in the way the data is written via Put in VB6.

In regards to rounding, most floating point numbers are represented in the way you described. Are you concerned that VB6 encodes floating point numbers in a non-standard way? Visual Basic uses the IEEE 754.


Useful IEEE-754 calculator: http://babbage.cs.qc.cuny.edu/IEEE-754/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top