PDA

View Full Version : Adding fields dynamically


ABC123

hernan
07-30-2010, 06:24 PM
Need to create a file with more than 600 fields,with field names "F1...Fn" and n to 600. No luck using Table.Field_add and evaluateString() Etc.

Tim Kiebert
07-30-2010, 07:28 PM
You haven't given details on wether the field properties are the same for all fields.

Here is an example that works and should give you some ideas.


dim fldList as C = ""
dim flname as C = a5.Get_Path() + "\zzzz.dbf"

'Table.create will overwrite an existing table of the same name so check if one exists.
if file.exists(flname) then
If ui_msg_box("Adding a table","Caution this table already exists. Overwrite?",UI_ATTENTION_SYMBOL+UI_YES_NO) <> UI_YES_SELECTED then
end
end if
end if

'Create the second and subsequent lines in the field list
'The first field is created by table.create_begin()
For i = 2 to 6
fldList = fldList + "table.field_add(\"F"+i+"\",\"c\",20)" + crlf()
Next

msgbox(fldList) 'Just for testing

'create the table
table.create_begin("F1","c",20)
evaluate_template(fldList)
tbl = table.create_end(flname)

'Add the table to the current application
file_add_to_db(flname)

hernan
07-31-2010, 07:56 AM
All fields will have the same properties.

Your code worked like a sharm! Plus studying it has increased my knowledge. Thanks a lot Tim.

Regards,

HernĂ¡n

DaveM
08-02-2010, 10:38 AM
Hernan,

Do you live in the Miami area?


.