You want to create a cursor with 50 or 100 fields to mimic a table with the same structure.
Let s suppose that the table you want to mimic is called "cata".
Put the following code in the command window:
for x=1 to fcount()
Highlight the 6 lines and press enter.
Now in your editor write the following code:
create cursor catanew ;
and now hit ctrl+V and you have instantly written the whole structure.
Thats perfect, I needed the structure in code for some temporary tables, I didn't want to open a table in this code at all but needed the structure, this has saved me some work, cheers.
oh one last thing, you can put a trim around that str() to tidy it a bit.
One could also try ...
SELECT * FROM cata WHERE 1=2 INTO CURSOR catanew READWRITE
I like using AFields() as you can keep the array and use it later
lnFields = AFields(laFields,"Cata")
then you can ;
CREATE CURSOR CataNew FROM ARRAY laFields
Cursor made this way are ReadWrite also
If you want to store the Array created by AFIELD(laStructure) use
SAVE to cursorStruc.mem a´ll like laStructure
Then if you want to reuse the structure
RESTORE FROM CURSORSTRUC.MEM ADDI
CREATE CURSOR|TABLE myTable FROM laStructure
If you want to store more than one table's structure you should use a table instead of a file
for every save structure array. The structure of this table
create table StructureTable (cTable c(25), structure m nocptrans )
I never cease to be amazed at the number of different ways to do the same task in Foxpro.
As for myself, I have always used the following;
Copy Structure to newtable
You now have a new empty table
While this is by far the easiest way to create an empty "dbf", I believe the original intent was to create a cursor (ie. temp, no ERASE or DELETE required after closing, etc.) -- Randy Jean
Category Code Samples
Contributors Eduardo Díaz Guerrero, Jim Booth, Tim Hustler, LucienTElliot, Randy Jean
( Topic last updated: 2005.06.15 08:08:09 PM )