Qbasicnews.com

Full Version: converting quickbasic random file in to xml using java
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi all
I am writing a utility program in java that reads a quickbasic random access file and creates an XML file from it. This random access file is created by an old quickbasic application.

The format for the random file is

OPEN in$ FOR RANDOM AS #1 LEN = 50
FIELD #1, 4 AS l1$, 4 AS d1$, 4 AS l2$, 4 AS d2$, 2 AS T1$, 2 AS R1$, 30 AS BE$

here l1,d1,l2 and d2 are float values(4 bytes)
T1 and R1 are short integers (2 bytes)

This file is read as

GET #1, a
l = CVS(l1$): d = CVS(d1$): l2 = CVS(l2$): d2 = CVS(d2$): t = CVI(T1$): R = CVI(R1$)

I am able to convert the short integers in to java but am facing problem in converting the float values.
Can any one please help me. I would lke to know how float is stored in quickbasic.
If the float values you are trying to read in are stored as strings you should be able to do this:
Code:
float f = Float.valueOf(floatString);
thanks for your reply
i had tried converting as you said but it didnt work.
later i figured out a solution myself.
here is it.it was a problem with byte ordering.qbasic uses little endian and java uses bigendian representations.i came aound this and now i am able to access the float values from java

the piece of code that worked is


byte bl1[]=new byte[4];
file.read(bl1);
float l1=ByteBuffer.wrap(bl1).order(ByteOrder.LITTLE_ENDIAN).getFloat();



again thanks a lot for your comment