-=> Bong Benitez schreef op 18 Jun 97 14:12:16 aan ALL over Adding Fields in
Clipper 5.2..<=-
BB> NAME.DBF
BB> LASTNAME C 10
BB> FIRSTNAME C 10
BB> MID C 1
BB>
BB> Fields to be added:
BB> ADDRESS1 C 40
BB> ADDRESS2 C 40
BB>
BB> First the program will detect the NAME.DBF if the new fields are
BB> present. If not the new fields will be added.
BB>
//---Detecting:
aRay := DBSTRUCT ( "NAME.DBF" )
log := .f.
FOR d = 1 to LEN aRay
IF "ADRESS" $ UPPER( aRay[ d ][ 1 ] )
//---Log becomes true if a field named ADRESS exists
log := .t.
ENDIF
NEXT
IF ! log //---There were no fields named ADRESS...
//-----Appending fields to database
AADD( aRay , { "ADRESS1" , "C" , 40 , 0 })
AADD( aRay , { "ADRESS2" , "C" , 40 , 0 })
//---Creating a new database
dbCreate( "NewName.Dbf" , aRay )
ENDIF
//---Appending existing records
CLOSE databases
USE NewName NEW
APPEND FROM name
CLOSE dataBases
ERASE name.dbf
RENAME NewNAme.dbf TO name.dbf
//---Deleting existing NTX's
ntx := DIRECTORY( "*.NTX")
FOR d = 1 to LEN( ntx )
ERASE( ntx[ d ][ 1 ] )
NEXT
///---EndOfFile
...Not tested, produced from the top of my head, but I think it should
do the trick.
I always reconstruct NTX's whenever I performed this kind of
operations on a DBF. Just in case...
Further you should declare all variables as LOCAL.
Be shure to check for a valid criterium to decide if the database
should be appended. In this code I check for the existance of the
string ADRESS within the array of fieldnames. But if a field like
B_ADRESS would have existed, there would be no appending of the new
fields.
Good Luck!
Cu,
Ron
--- Blue Wave v2.12
---------------
* Origin: SYNCNET BBS - +31-35-6237178/6244318 [ISDN] (2:283/1)
|