Solved

Translate Basic "GET" & "FIELD"

Posted on 2002-07-18
4
200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ Class Serialization, Encapsulation and Formatted Output 8 90
No module found pypyodbc, 3 43
Need some help with mailto 16 31
print bytes of an integer 6 21
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

685 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