Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help With Importing Text File
Message
From
18/06/2003 09:13:48
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
18/06/2003 08:30:35
Julie Ball
Gardner Publications, Inc.
Cincinnati, Ohio, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00801114
Message ID:
00801125
Views:
9
This message has been marked as the solution to the initial question of the thread.
>I have a text file that contains compy info records that I need to import into FoxPro. Easy enough. Well the problem is, is that this file has the records input a little different. Instead of having a company, address, phone, fax info as different fields; it displays each field as a different record. How it is displayed is:
>ABC Company
>123 West St
>Some City, OH 55555-5555
>Phone: 555-555-5555 Fax: 555-555-5555
>
>There is a blank after each company record. How do I go about importing these files into a dbf but have each company record display in it's correct fields?
>
>Thank you,
>Julie

Julie,
As always there are multiple ways. Assuming it has no more than 65000 lines :
lnLines = alines(arrContent,FileToStr('importme.txt'))
lnLinesPerRecord = 4+1 && 1 blank
lnRows = ceiling(lnLines/lnLinesPerRecord)
dimension arrContent[lnRows,lnLinesPerRecord]
For ix=1 to lnLinesPerRecord
  If Type('arrContent[lnRows,ix]')='L'
    arrContent[lnRows,ix] = ''
  endif
endfor
Select myTable
Append From array arrContent
Another way might be do some xml processing. ie:
lnHandle = Fopen('importme.txt')
Set Textmerge To importme.XML Noshow
Set Textmerge On
\\<?xml version = "1.0" encoding="Windows-1252" standalone="yes"?>
\<VFPData>
Do While !Feof(lnHandle)
	\<myTable company="<<Fgets(lnHandle,4096)>>" address="<<Fgets(lnHandle,4096)>>"
	\\ CityState="<<Fgets(lnHandle,4096)>>"
  lcPhoneFax = Fgets(lnHandle,4096)
	\\ Phone="<<StrExtract(lcPhoneFax,'Phone:','Fax:')>>"
	\\ Fax="<<Substr(lcPhoneFax,Atc('Fax:',lcPhoneFax)+Len('Fax:'))>>">
  If !Feof(lnHandle)
    Fgets(lnHandle)
  Endif
Enddo
\</VFPData>
Set Textmerge To
Set Textmerge Off
Fclose(lnHandle)
You could rectify code and (add a table schema) then XmlToCursor().
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform