PUBLIC LastID SET talk OFF SET COLOR TO SET DECIMALS TO 6 CLEAR desth='ALL_HEAD' destd='ALL_DATA' ianswer='Y' @1,1 say 'To which main header file ? ' @2,1 say ' data file ? ' @3,1 say '-------------------------------------' @1,1 say 'To which main header file ? ' get desth picture '!!!!!!!!' message 'The main header file of PosDat.' READ pos=at('HEAD',desth) destd=IIF(pos=0,' ',stuff(desth,pos,4,'DATA')) @2,1 say ' data file ? ' get destd picture '!!!!!!!!' message 'The main data file.' read DO WHILE ianswer$'Yy' CLOSE DATABASES sourceh='HEAD ' sourced='DATA ' @4,1 say 'From which header file ? ' get sourceh picture '!!!!!!!!' message 'The name of the header file you want to append to a main file.' @5,1 say ' data file ? ' READ pos=at('HEAD',sourceh) sourced=IIF(pos=0,' ',stuff(sourceh,pos,4,'DATA')) @5,1 say ' data file ? ' get sourced picture '!!!!!!!!' message 'The data file.' READ IF (.NOT.file(desth+'.DBF')).OR.(.NOT.file(destd+'.DBF')) @7,1 SAY 'Creating new main header and data files...' USE &sourceh copy stru to &desth USE &sourced copy stru to &destd ENDIF IF file(sourceh+'.DBF').AND.file(sourced+'.DBF') @8,1 SAY 'Appending header records...' select 1 use &desth alias dh go bott select 2 use &destd alias dd go bott SELECT 1 if reccount()=0 then LastID='AA@' HeaderNO=1 else LastID=ID HeaderNO=RECNO()+1 endif append from &sourceh SELECT 2 if reccount()=0 DataNO=1 else DataNO=RECNO()+1 endif append from &sourced CLOSE DATABASES USE &sourceh go top USE &desth go HeaderNO OriginalID=LastID CurrentID=ID DO WHILE .NOT.EOF() do IncID replace ID with LastID skip ENDDO @8,53 SAY str(reccount(),6,0)+' records in total.' USE &sourceh @8,28 SAY str(reccount(),6,0)+' records appended,' @9,1 SAY 'Appending data records...' USE &destd go DataNO LastID=OriginalID CurrentID=' ' DO WHILE .NOT. EOF() IF CurrentID<>ID do IncID CurrentID=ID ENDIF replace ID with LastID skip ENDDO @9,53 SAY str(reccount(),6,0)+' records in total.' USE &sourced @9,28 SAY str(reccount(),6,0)+' records appended,' CLOSE DATABASES ELSE @8,1 TO 8,80 CLEAR @9,1 SAY 'Source file does not exist. ' ENDIF ianswer=' ' DO WHILE .NOT.(ianswer$'NYyn') @11,1 SAY 'Append another file (Y/N)?' GET ianswer PICTURE "!" READ ENDDO ENDDO &&--------------- BIG ENDDO of MORE THAN ONE FILE ----- CLEAR SET DECI TO return PROCEDURE IncID iidq1=asc(LastID) iidq2=asc(substr(LastID,2,1)) iidq3=asc(right(LastID,1)) iidq3=iidq3+1 IF iidq3>90 iidq3=65 iidq2=iidq2+1 IF iidq2>90 iidq2=65 iidq1=iidq1+1 IF iidq1>90 iidq1=48 && USE ALSO NUMBERS iidq2=65 iidq3=65 ENDIF ENDIF ENDIF LastID=chr(iidq1)+chr(iidq2)+chr(iidq3) return