Link to home
Start Free TrialLog in
Avatar of Glenn Stearns
Glenn StearnsFlag for United States of America

asked on

How to add existing dbf files to a new database (dbc)

I have several tables created in an earlier version of FoxPro (table1.dbf, table2.dbf, etc.); however, they only exist as tables and are not part of a database (.dbc). I know I can create a new database with the CREATE DATABASE command and I can ADD TABLE if I want to make a new, empty table.  But, what I want to do is add these existing .dbf files to the new database (newdatabase.dbc) file in FoxPro 9. Each one of these existing tables is also indexed with a .mdx file. Can you provide the VFP code steps needed to do this?
Avatar of tusharkanvinde
tusharkanvinde
Flag of India image

You can use ADD TABLE to add an existing table. Don't know about .mdx file. VFP does have to capability to convert indexes from dBase.
Avatar of Glenn Stearns

ASKER

I know I need to use ADD TABLE. What I want is the ADD TABLE syntax using the variable names provided in my question.
By variable name do you mean "table1.dbf" etc?

You can use macro substitution e.g.

tablename = "table1.dbf"
add table &tablename
The code should add all dbf files in the folder into a database.
CREATE DATABASE YourDatabase
FOR lnCounter=1 to ADIR(laFile,'*.DBF')
    ADD TABLE (laFile[lnCounter,1])
ENDFOR

Open in new window

I cannot get the macro substitution to run. Error: Command contains unrecognized phrase/keyword. I typed it into the command window just like shown.

On the CREATE DATABASE code lines - how does the FOR command know where the database files are located?  They are located in C:\TABLES.
It was for the default folder. so give command
set default to c:\tables

before the other code
ASKER CERTIFIED SOLUTION
Avatar of ramrom
ramrom
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial