Solved

Translate Basic "GET" & "FIELD"

Posted on 2002-07-18
4
199 Views
Last Modified: 2010-04-01
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!
0
Comment
Question by:Kory
  • 2
4 Comments
 
LVL 12

Expert Comment

by:pjknibbs
ID: 7164140
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.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7164436
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
0
 

Author Comment

by:Kory
ID: 7168235
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
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 300 total points
ID: 7197678
FIELD lays out a chunk of memory as a series of BASIC variables.  GET fills that memory with data from disk.  Right after using GET, you can access the variables and they will have the values read from disk.

Surely you have access to a BASIC manual of some sort... I'm certain that this is all described there.

But given the constraints you described (must run on some oddball hardware), what you really need to do is stop trying to translate the BASIC code.  Instead, rewrite the file I/O portions of the program from the ground up.

-- Dan
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question