Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i read data from a text file

Status
Not open for further replies.

skyyonk

Programmer
May 6, 2002
23
0
0
SG
Hi all,

I have data in a text file which i would like to extract and store into a foxpro table. A sample of the file header is shown below.

------------------------------------------------------------------------------------------------------------------------------------
Account Trans Reference Amount Journal Journal Due Description A n a l y s i s C o d e s
Period Date Type No. Line Date Alloc CTR GST INTER REF
------------------------------------------------------------------------------------------------------------------------------------
 
Skyyonk,

Basically, you need to do an APPEND FROM. If the width of each field in the text file is fixed, it'll be APPEND FROM ... TYPE SDF. If you have tabs or some other delimiter between the fields, try APPEND FROM ... TYPE DELIMITED WITH ...

The Help will tell you more.

Mike


Mike Lewis
Edinburgh, Scotland
 
Skyyonk,
if your text file is report with twolines detail,
create table with one char field lenght as report line,
APPEND FROM ... TYPE SDF,
parse this char field, each line separately with SUBSTR,
filtering header and footer lines with apropriate func,
for example VAL(SUBS(...))=0
Tesar
 
If the text file you are importing from might have descriptive headers or footers (such as titles, page numbers, totals, etc.) then be aware that after the import your code should check for and handle such issues.
 
In addition to what the others have said, if the data in
each logical column of your text file is variable in
length, you'll probably need to pre-process the input file
before you append. i.e. add delimiters yourself or adjust
line length.

Also, I noticed the top portion of what appears to be a report header.

This type of information will make it almost impossible to
get a good append. You'd need to strip this information out
of the text file before appending.

There are many other exceptions to consider, so without a
better understanding of what the text file looks like and
what the underlying table structure is, it's hard to say more.

In addition, I've noticed in my work that when appending
from a text file using the 'type sdf' clause to the append
command, and the text in the file includes a column that
will be converted to type 'date', the resulting date field
in the table will be munged. If the date field in the
table is changed to datetime the resulting data comes in
fine.

Darrell

'We all must do the hard bits so when we get bit we know where to bite' :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top