Reading a binary random search file created in QB4.5

General FreeBASIC programming questions.
Post Reply
BernyD
Posts: 2
Joined: Dec 16, 2009 5:39
Location: Los Angels, Ca.

Reading a binary random search file created in QB4.5

Post by BernyD »

Hello Everyone,

I need to be able to read and write to a binary cross reference that was created in QB4.5. The UDT consist of fixed length strings, intregers and singles.

Thanks,
BernyD
an old nooby
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Post by Antoni »

Your old QB program should "almost" work with the addition of #lang "qb" at the start , if it was'nt for an old design flaw in FB .

The fixed lenght strings in UDT's loose their last char, as FB stubbornly uses it as an end of string marker and erases it .

So the only way to read correctly packed UDT's from a file is to change the string*x declarations to ubyte arrays and use special routines to copy the bytes to and from external fixed length string buffers before processing. Fixed length strings outside UDT's are working correctly.
Qlink
Posts: 79
Joined: Jun 06, 2007 15:21

Post by Qlink »

Why does FB still use string terminators for fixed length strings? Doesn't that seem like a waste of memory?
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Post by counting_pine »

The memory wastage is the least of its problems. In fact I can't think of a simple redeeming feature, apart from simplicity on the part of the compiler. I'd like to see it go as much as anyone else, but it will take work.
jevans4949
Posts: 1188
Joined: May 08, 2006 21:58
Location: Crewe, England

Post by jevans4949 »

If reading QB-type fixed strings, change your UDT to ztrings of the same length, and use left(s,len(s)) to access the whole string.

To write back to a fixed string to be read by QB, format the content in a longer zstring, concatenating space(len(s)) to pad out with spaces, then use the memcpy function from the CRT library to move to target. See C Standard Library in the help files.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Post by counting_pine »

jevans4949 wrote:If reading QB-type fixed strings, change your UDT to ztrings of the same length, and use left(s,len(s)) to access the whole string.
IIRC, that method will read in the following memory up to the first null byte - if there is one.
Unfortunately there isn't a good way of doing it at the moment, and the safest pure-FB method is probably to use byte arrays and For-loops for conversion.
BernyD
Posts: 2
Joined: Dec 16, 2009 5:39
Location: Los Angels, Ca.

Post by BernyD »

Thank you all for your replies.

As I read your replies I realized that the question I asked was not exactly what I meant.

The cross referance file will not need to be read by a QB program anymoreas it will be have to be abandended altogether. Actually finding FB is quite lucky (I wish it had happened years ago).

The programs I run have outgrown the IDE to the point that adding code or data cause it to crash.

Just before the holidays MIS upgraded my pc to a workstation and no one is old enough to remember how to install an extended DOS window on XP.

So, my goal is to move completely to FB. I have a text version of the crossref. Could it be read into FB loaded, parsed and output to a FB binary style file?

Alternately this information also exists in a MS Access 2003 database.

Thanks
BernyD
jevans4949
Posts: 1188
Joined: May 08, 2006 21:58
Location: Crewe, England

Post by jevans4949 »

The answer is, basically, yes. All those data formats are available in FB. Note that
(1) fixed STRINGS are basically stored in in similar manner to ZSTRINGs, as discussed,
(2) the default INTEGER is 32-bit; for 16-bit use SHORT;
(3) Floating-point numbers are IEEE format; the original GW-Basic format is not supported.
Post Reply