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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Dbase file from scratch using program 1

Status
Not open for further replies.

ddelk

Programmer
May 28, 2003
47
US
I do not want to make a structure file then use CREATE <FILE> FROM <STRUCTURE FILE>. I want to create a dbase file out of thin air using a dbase program. Is this possible?
 
What version of Dbase are you using?

If you use in your code set sql on (or set seaqual, cant remember) then you should be able to create tables using sql commands.

ChaZ

"When religion and politics ride in the same cart...the whirlwind follows."
Frank Herbert
 
The old FoxPro (at least as far back as 2.6) allowed you to programmatically create a table and all it's fields. DBase for DOS was simpler. What you could do is create a table and manually enter all the field names, types, lengths, decimals and index. Not something you'd want all the users to be doing on a daily basis, but it's the best that comes to mind.
Code:
newTable = "test_123"

* option #1 (best)
CREATE (newTable)

* option#2 (always avoid macrosubstitution whenever possible - slower)
CREATE &newTable
Blorf mentions using SET SQL ON/OFF to activate the SQL environment. I've never tested that, but one quirk was that when you were in SQL mode, only an allowed subset of dBase commands could be used, so I stayed away from it. Also, version 5's manual said "You cannot use SQL ON/OFF in a program.
 
Thanks for the help. I am using Dbase IV, v2.0. Should've mentioned that.
 
It appears, unfortunately, that you can't use SQL commands in a program. I get a command not allowed error.
 
Hi

I am pretty sure there is no easy way without using CREATE <FILE> FROM <STRUCTURE FILE> etc as you woul need to start with a .dbf table of sorts, but you could still generate a .dbf table programmatically using a dummy table for starters.

1. Your dummy table would have to have the fields FIELD_NAME, FIELD_TYPE, FIELD_LEN, FIELD_DEC and FIELD_IDX.

2. Start with no records in this dummy table

3. use APPEND BLANK to add a record (which later becomes a field)

4. Examples of field types are below
FIELD_NAME FIELD_TYPE FIELD_LEN FIELD_DEC FIELD_IDX
MYFIELD1 N 6 0 Y
MYFIELD2 N 6 2 N
MYFIELD3 C 5 0 N
MYFIELD4 M 10 0 N
MYFIELD5 L 1 0 N
MYFIELD6 D 8 0 N

5. Close this dummy table

6. Then issue the CREATE <FILE> FROM <STRUCTURE FILE> command.

Then you can generate any table with any number of records from this.

If you are talking about creating a table using low-level coding, then thats another issue, but why would you when this could be as good a way as any?

Hope this helps
 
ddelk, You can't run SQL in a program. You have to type SET SQL ON/OFF from the command prompt.

Ormsk, I gave you a star. It's as good a workaround as we'll ever get on these older versions. A lot of coding to do it, but it's the only way to automate or preprogram it.
 
Well at least I can just have one structure file instead of one for every instance that I need one. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top