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

How to create a table without using CREATE TABLE 1

Status
Not open for further replies.

badscots

Programmer
Dec 23, 2003
19
GB
Hello all,

I have a form that a user defines a sructure for a table. These values are stored in a list and I wish to use these values and create a table, then import the data file they have chosen.

Any Ideas???

Tx's in advance.

Mac.
 
I assume you mean "how do you create a table programmatically". For that, look up the "Create table - sql" command and simply use &variablename for each field name.

Let's say field1 is an integer in table1 (so you have table1.field1).
You would put this in your .prg:
field1=table1.field1
field1type=table.fieldtype

create table whatever (&field1 &fieldtype)

You could also do a for/next with N being equal to the number of records in your field descriptions table and create a string of fields separated by commas in order to allow for unlimited/unknown field counts.
 
As previously stated - not sure what you really want. Maybe something like this?

Create table mytable (Field1 C(20), Field2 N(8,2), Field3 L, Field4 M, Field5 D)

append blank
REPLACE field1 with "Sammy Sample"
REPLACE field2 with 534.34
REPLACE field3 with .T.
REPLACE field4 with "HELLO WOLRD from Sammy Sample"
REPLACE field5 with DATE()
BROWSE

* USE
* DELETE FILE mytable.dbf

Jim Osieczonek
Delta Business Group, LLC
 
Mac.,
I think what you may be looking for is:
Code:
CREATE TABLE userstable from ARRAY myTableinfo
Where "myTableinfo" is an array as defined in AFIELDS() - see your version of FoxPro for the details. The size of the row is version dependent.

Rick

 
Thanks Guys!!!

NoWayIsThisInUse: This was exactly what I was looking for.

Many thanks for your help :)

Mac
 
I just thought of something else from way back when.
Do this from the command prompt.
use anytable
copy structure extended to newtable

Take a look at the fields it creates.
Your work table that your users are adding info to should mirror these field layouts (not the data -- the structure "field_name", "Field_type", etc.).

After you add a record to this table, you've really added a complete field description. You put the field name like "Lastname" in the field_name field, etc.
Now, simply issue a CREATE FROM newtable....
command and it will create a new table with the structure you need. These are old commands I haven't used in a long time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top