Adding a field during execution without setup 
Author Message
 Adding a field during execution without setup

I know two way to add a field in a DBF (Fox 2.6)

1) Menu Database - Setup
        Problem : only manually
2) SQL clausure - use CREATE
        Problem : create an entire structure

I need add only one field during a program execution !

Thanks for any help ...



Wed, 02 Jan 2002 03:00:00 GMT  
 Adding a field during execution without setup
Yes, it can be done.

USE Table1
afield(latemp)
*dime latemp[alen(latemp, 1)+1,16]    && VFP
dime latemp[alen(latemp, 1)+1,4]

Now write a routine to assigne a Fieldname, Type, Len, and
Dec to the last row in the array. The last row in the
array is ALEN(laTemp, 1)
lnRow = ALEN(laTemp, 1)
laTemp(lnRow, 1) = <field>
laTemp(lnRow, 2) = <type>
laTemp(lnRow, 3) = <len>
laTemp(lnRow, 4) = <dec>

Now use this command:
CREATE TABLE | DBF TableName1 [NAME LongTableName] [FREE]
 (FieldName1 FieldType [(nFieldWidth [, nPrecision])]
  [NULL | NOT NULL]
  [CHECK lExpression1 [ERROR cMessageText1]]
  [DEFAULT eExpression1]
  [PRIMARY KEY | UNIQUE]
  [REFERENCES TableName2 [TAG TagName1]]
  [NOCPTRANS]
 [, FieldName2 ...]
  [, PRIMARY KEY eExpression2 TAG TagName2
  |, UNIQUE eExpression3 TAG TagName3]
  [, FOREIGN KEY eExpression4 TAG TagName4 [NODUP]
   REFERENCES TableName3 [TAG TagName5]]
  [, CHECK lExpression2 [ERROR cMessageText2]])
| FROM ARRAY ArrayName

This is from the help file in 5.0 but the command is the
same in 2.x except for the [LongName]

best...

Quote:

> I know two way to add a field in a DBF (Fox 2.6)

> 1) Menu Database - Setup
>         Problem : only manually
> 2) SQL clausure - use CREATE
>         Problem : create an entire structure

> I need add only one field during a program execution !

> Thanks for any help ...

--
Shar Feldheim, President
PC Software, INC  - Visual Foxpro Application Development
"Programs are NOT foolproof...the fools are TOO ingenious"

***************************************************





Wed, 02 Jan 2002 03:00:00 GMT  
 Adding a field during execution without setup
Gotta love these esoteric solutions <g>
Here are some simpler fox commands to do the same thing

use original file
copy struc exten to temp
use temp
append blank
replace field_name with "new field",field_type with "C",field_len with
whatever
(field type is Character,number etc.   There is also a field_dec for numeric
decimals)
create "new_file" from temp
append from original file
use new_file alias original file

The original indexes will still work with this file and the memos

You can also have a system file set up with a one of each type of field and
use it in a select statment by selecting all fields from the original file
plus one of more fields from the system file.   You can create new fields
using the AS option in a select by definition but I find it simpler to use a
system file to provide the exact structure of the new field

select all
originalfile.field1,originalfile.field2,systemfile.character_field as
new_field_name from originalfile, systemfile into table new table
close original file
use new file alias original file
The indexes will need to be created again for this method.

Using any of these methods creates a new file and you will still have to get
rid of the old file and rename the new one, which I suspect does not really
solve your original question.

Another method which will create a new record on the fly is to create and
run a keyboard macro.
The following macro will create a "new" character field with a default
length.  The file must be used exclusively
MODI{SPACEBAR}STRUC{ENTER}
{UPARROW}NEW{TAB}{TAB}{TAB}{CTRL+W}Y

Al.


Quote:
>Yes, it can be done.

>USE Table1
>afield(latemp)
>*dime latemp[alen(latemp, 1)+1,16]    && VFP
>dime latemp[alen(latemp, 1)+1,4]

>Now write a routine to assigne a Fieldname, Type, Len, and
>Dec to the last row in the array. The last row in the
>array is ALEN(laTemp, 1)
>lnRow = ALEN(laTemp, 1)
>laTemp(lnRow, 1) = <field>
>laTemp(lnRow, 2) = <type>
>laTemp(lnRow, 3) = <len>
>laTemp(lnRow, 4) = <dec>

>Now use this command:
>CREATE TABLE | DBF TableName1 [NAME LongTableName] [FREE]
> (FieldName1 FieldType [(nFieldWidth [, nPrecision])]
>  [NULL | NOT NULL]
>  [CHECK lExpression1 [ERROR cMessageText1]]
>  [DEFAULT eExpression1]
>  [PRIMARY KEY | UNIQUE]
>  [REFERENCES TableName2 [TAG TagName1]]
>  [NOCPTRANS]
> [, FieldName2 ...]
>  [, PRIMARY KEY eExpression2 TAG TagName2
>  |, UNIQUE eExpression3 TAG TagName3]
>  [, FOREIGN KEY eExpression4 TAG TagName4 [NODUP]
>   REFERENCES TableName3 [TAG TagName5]]
>  [, CHECK lExpression2 [ERROR cMessageText2]])
>| FROM ARRAY ArrayName

>This is from the help file in 5.0 but the command is the
>same in 2.x except for the [LongName]

>best...


>> I know two way to add a field in a DBF (Fox 2.6)

>> 1) Menu Database - Setup
>>         Problem : only manually
>> 2) SQL clausure - use CREATE
>>         Problem : create an entire structure

>> I need add only one field during a program execution !

>> Thanks for any help ...

>--
>Shar Feldheim, President
>PC Software, INC  - Visual Foxpro Application Development
>"Programs are NOT foolproof...the fools are TOO ingenious"

>***************************************************






Wed, 02 Jan 2002 03:00:00 GMT  
 Adding a field during execution without setup


Quote:
> I know two way to add a field in a DBF (Fox 2.6)

> 1) Menu Database - Setup
>         Problem : only manually
> 2) SQL clausure - use CREATE
>         Problem : create an entire structure
> I need add only one field during a program execution !
> Thanks for any help ...

Is the ALTER TABLE, SQL command available in ver 2.6?
If it is you coluld just :
****
ALTER TABLE mytable ADD COLUMN myfield c(10) NULL
****

--
Per Wicken



Thu, 03 Jan 2002 03:00:00 GMT  
 Adding a field during execution without setup
Ro
Check out the command ALTER TABLE command. For example
ALTER TABLE x ADD COLUMN y C(15)
-Anders



| I know two way to add a field in a DBF (Fox 2.6)
|
| 1) Menu Database - Setup
|         Problem : only manually
| 2) SQL clausure - use CREATE
|         Problem : create an entire structure
|
| I need add only one field during a program execution !
|
| Thanks for any help ...
|
|
|



Thu, 17 Jan 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Memorizing form configuration during program execution

2. modify the click event during execution

3. Creating textboxes during program execution

4. scanning during add record

5. Files installed to Windows during setup.

6. Copying fonts to Windows System during setup

7. error during setup wizard

8. Explicit Execution of Field-Level Valid code

9. Help: Distributing a VFP3 *.exe without the Setup Wizard

10. Help - VFP5 Creating setup disks without a debugger

11. distributing VFP5 application without setup

12. Installing VFP-Apps without MS-Setup Wizard

 

 
Powered by phpBB® Forum Software