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?
Glenn StearnsAnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tusharkanvindeCommented:
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.
Glenn StearnsAnalystAuthor Commented:
I know I need to use ADD TABLE. What I want is the ADD TABLE syntax using the variable names provided in my question.
ramromconsultant Commented:
By variable name do you mean "table1.dbf" etc?

You can use macro substitution e.g.

tablename = "table1.dbf"
add table &tablename
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

tusharkanvindeCommented:
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

Glenn StearnsAnalystAuthor Commented:
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.
tusharkanvindeCommented:
It was for the default folder. so give command
set default to c:\tables

before the other code
ramromconsultant Commented:
Should have been:

tablename = "table1"
add table &tablename

or

add table (tablename)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
FoxPro

From novice to tech pro — start learning today.