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!

Backward compatible .dbf files 3

Status
Not open for further replies.

PatMcLaughlin

Programmer
Dec 10, 2010
97
US
We have a legacy program built with Foxpro for Windows 2.6 that is still in use and not giving us any problems... until now. It uses data from a dbf file that we have recently changed to use foxpro 9.0 to create. The Foxpro 9 creates the dbf which is called zipcode_dnld.dbf and once created, it copies it to another directory used for production and names it zipc.dbf. It also copies its .cdx file. It will open and looks as expected in Foxpro 9.0 but when the 2.6 program attempts to use it it throws the error... "Not a table/DBF". Is there a way to have the Foxpro 9 continue to build it and copy it in a way to allow 2.6 to use it?
 
Code:
Copy to zipc.dbf fox2x
should do it


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
You have hit upon one of the main incompatibilities between FPW 2.x and VFP. Essentially, VFP can read and write DBFs created in 2.x. And 2.x can read DBFs that have been written to by VFP. But 2.x can't read files that were created in VFP, or where VFP has modified their structure.

Fortunately, there is an easy workaround. In VFP, create a copy of the DBF using this command:

Code:
SELECT MyFile
COPY TO MyFile2x TYPE FOX2X

Note that it the file has any data types that are specific to VFP (such as Currency and DateTime) these will be lost. If the file is in a DBC within VFP, long field names will be truncated, and DBC properties (such as Caption) will be lost. See the Help for COPY TO for more details.

Once you've done the above, the new file (MyFile2x in this example) can be opened, read and written by 2.x.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Do you need the word TYPE?

Don't worry about staying awake, just don't let your head drop onto the keyboard.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Hi,

Below the full command

Code:
COPY TO FileName 
        [ DATABASE DBCName [ NAME LongTableName ] ]
        [ FIELDS FieldList  
         | FIELDS LIKE Skeleton 
         | FIELDS EXCEPT Skeleton ]
        [ Scope ] [ FOR lForCondition ] 
        [ WHILE lWhileCondition ]
        [ [ WITH ] CDX | [ WITH ] PRODUCTION ]
        [ NOOPTIMIZE ]
        [ [ TYPE ] FOXPLUS | FOX2X | DIF | MOD | SDF | SYLK
         | WK1 | WKS | WR1 | WRK | CSV | XLS | XL5
         | DELIMITED [ WITH Delimiter | WITH BLANK 
         | WITH TAB ] [ WITH CHARACTER Separator ] ]
        [ AS nCodePage ]

As you can see "TYPE" is optional

MarK
 
Thank you to ALL for the very quick responses! I used
Code:
COPY TO myfile WITH CDX TYPE FOX2X
and I got a readable file with the index. Perfect! You guys have done so much, with so little, for so long that you can now do ANYTHING with nothing in half the time!
 
And if you only had half as much fun today as I had, I had double the fun of you.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top