Link to home
Start Free TrialLog in
Avatar of Kory
Kory

asked on

Translate Basic "GET" & "FIELD"

I need to find some way to create a function/class that works the same as the basic "GET" and "FIELD" commands.

Get: Read a specific record from a file into a buffer

Field: Basicly a fixed sized record which can be looked at different ways. (idea is kind of like a union)
Ex: RecordA size=10
   Field RecordA, 10 as FULL_REC
   Field RecordA, 5 as A, 5 as B
   Field RecordA, 2 as A, 8 as B

I was thinking of implementing the "GET" by:
  Reading it into a homemade string class.

Then implementing the "FIELD" by:
  "Pointing" a homemade fixed length string at the specific index

Does anyone know of a premade translator that already (and correctly) translates these commands? Or does anyone have any ideas that could be helpful?

Thanks in advance!
Avatar of pjknibbs
pjknibbs

You basically want a text-based data storage system? Why not use XML? It's a standard, and there's plenty of software available for free which allows you to read and write files in this format.
Avatar of DanRollins
Although I haven't heard old fashioned commands like GWBASICS's GET and FIELD statement in many years, I have often done exactly what you are describing.

There are several ways to attack the problem.  BASIC's GET and PUT can work with binary values.  Will you be reading and writing binary values?  Or is everything text?

Will you me using MFC?  Or are you using a compiler other than VC++?

If you are using VC++ and MFC and the data is all text, you can use code like this:

First, open the file and read in the expected record length into a char buffer (do you need help with this?)

Next, assign a CString to that data:

CString sData= szInputBuf;  // assumes null terminated or
CString sData( szInputBuf, 24 ); // get 24 bytes

Now you can extract data easily in one of several ways.  Let's say that field # 3 (last name) starts at offset 17 and goes for 20 characters:

CString sLastName= sData.Mid( 17, 20 );
Or Lets say offset 12-17 is a decimal value like "1234"...
CString sTmp= sData.Mid( 12, 4 );
int nValue= atoi(sTmp);

I have a parser that does the above sort of thing based upon a table of offsets and lengths.  But I don't want to discusss that or other techniques, until I know more about what you already know and what compiler you are using, etc, as I have said above.

-- Dan
Avatar of Kory

ASKER

First off, we are transfering our information from a vax to an alpha, but also supporting Windows NT. (All the code was BASIC, going to C++) The code must compile on the alpha and in Microsoft's visual studio. We also are using our own (homemade) translator, written in perl.

We are unable to use C++'s CString data type because of the way it's stored in memory I believe. But we have our own Fixed, Dynamic, and SubString classes.

I do not know much about BASIC, and I also only know what the question says about the GET & FIELD commands. If you are able to share some info about those topics too, that would me majorly helpful too!

Thanks
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial