Solved

Translate Basic "GET" & "FIELD"

Posted on 2002-07-18
4
192 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now