Solved

Translate Basic "GET" & "FIELD"

Posted on 2002-07-18
4
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 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