Article ID: 176655
Article Last Modified on 6/29/2004
First Name Last Name State DOB Terms George Washington VA 2/22/1732 2 John Adams MA 10/30/1735 2 Thomas Jefferson VA 04/13/1743 2 James Madison VA 03/16/1751 2 James Monroe VA 04/28/1758 2 John Adams MA 04/11/1767 1 Andrew Jackson SC 03/15/1767 3
APPEND FROM <filename> TYPE DELIMITED
The APPEND FROM places one record in the table for each row in the text
file.
PARAMETERS nrows
USE ztable1.DBF
=AFIELDS(atbldata,"ztable1")
x=1
fname=""
STORE FOPEN('test.txt') TO hTextFile && Open the file.
STORE FSEEK(hTextFile, 0, 2) TO FileEnd && Move pointer to EOF.
STORE FSEEK(hTextFile, 0) TO FileTop && Move pointer to BOF.
IF FileEnd <= 0 && Is file empty?
WAIT WINDOW 'This file is empty!' NOWAIT
ELSE
FSIZE=FSEEK(hTextFile,0,2) && Determine file size.
=FSEEK(hTextFile,0,0) && Go to the top of file.
DO WHILE x <= nrows
APPEND BLANK
FOR i= 1 TO ALEN(atbldata,1) && Loop for each field in Array.
FieldData = FGETS(hTextFile, FileEnd) && Store contents in
&& a variable.
fname=ALLTRIM(atbldata(i,1)) && Trims blanks from data.
REPLACE (fname) WITH FieldData && Places data in .dbf
&& file field.
ENDFOR
x=x+1 && Increment counter for next field.
ENDDO
ENDIF
= FCLOSE(hTextFile) && Close the file.
DO Tbltodbf.prg with 7
Keywords: kbhowto KB176655