Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FoxPro Data Convertor

Status
Not open for further replies.

foxprox558

Programmer
Oct 19, 2013
53
US
Hi, As per the program I was previously working on, I have managed to get copies of the databases for the DOS program, and I'm making a converter to save time and effort, But the problem is: How do I tell the program to go to the next record without saying 'goto recno()+1', I tried that and got "Error, Record is out of range
 
Thanks! But do you know of a way that I can break this type of string into 2 variables?
in the old databases, it puts the firstname and lastname in the same field, my program separates them
Old database name format:[Field::Name] <lastname>, <firstname>
MY name database format:[Field::Last] <Last>
MY name database format:[Field::First] <First>
is there a way I can break the old database's names apart so I can properly put them into my database?
 
Foxpro is pretty uniquely great at data conversions because it has been around for so long and still has everything ever added to it.

In your case, you need to spend a bit of time in the help file. I think you'll find Left(), Right(), Substr(), At(), Rat(), Occurs() and possibly even GetWordNum() useful.

How to make them useful? Well, gosh, there are as many ways as there are people.
 
And ALINES() and STREXTRACT(). GETWORDNUM should be easiest to cope with, if you use the "," as the separator instead of the default (which would be any white space characters).

Bye, Olaf.
 
And also see all of the See Also links in all of the above help topics.
 
Here in detail, what I would do about the <lastname>, <firstname> containing field

Code:
USE Names.dbf
BROWSE FOR OCCURS(',',NVL(Name,''))<>1

No records show up? Fine! If records show, they either have no comma, or more than one or NULL as Name. Fix them. If there are lots of only last names, you may leave them as is, that won't matter, but if there are some names only first name, add a comma in front.

Code:
SELECT PADR(LTRIM(GETWORDNUM(Name,1,',')),LEN(Name)) As Last, PADR(LTRIM(GETWORDNUM(Name,2,',')),LEN(Name)) As First From Names INTO CURSOR curSeparated

This would make the conversion on the fly and also work for the corner cases, the previous field is fully used for either first or last name, the new fields in average only would need half the length, but it doesn't hurt to let each field - first and last - have the length of the former name field. You can shorten the fields later.

To put the result into a table either select...INTO TABLE or have a table with the two fields prepared empty and then do
Code:
INSERT INTO TABLE SeparatedNames (Last, First) ;
SELECT PADR(LTRIM(GETWORDNUM(Name,1,',')),LEN(Name)) As Last, PADR(LTRIM(GETWORDNUM(Name,2,',')),LEN(Name)) As First From Names

To create a 2.6 table instead keep it at INTO CURSOR, and then SELECT curSeparated bfore you do COPY TO NewTable.DBF TYPE Fox2x.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top