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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

import data

Status
Not open for further replies.

superprutser

Technical User
Nov 27, 2001
12
0
0
NL
I have to import data into a foxpro 2.6 database.
The original text file is separated with ;, when i try to append from i cant use the delimited function.

to be imported data:
37262;20040728;20040728;Servicedesk (-1);190000;
 
Hmm probably not with the ; char as foxpro sees this as a continuation of line chr. Though the VFP help says to specify APPEND FROM myfile.txt DELIMETED WITH ";" which is worth a try or alternately open the file in a text editor and replace all ; with say * then try APPEND FROM myfile.txt DELIMETED WITH *

Bob Palmer
The most common solution is H2O!
 
These threads may help:
thread182-667128 An earlier FoxPro thread
thread290-573484 Some ideas from a dBase thread

dbMark
 
Hi, you may want to change this code to fit your needs:

[tt]
cInFile = "testdata.txt"
cOutFile = "testdata.dbf"
cSeparator = ";"
nMaxColWidth = 25
nHandle = fopen(cInFile)
if nHandle < 0
wait window "Can't open file"
cancel
endif
cString = fgets(nHandle)
nFields = occurs(cSeparator, cString)
cFields = ""
for f = 1 to nFields
cFields = cFields + "fld" + ltrim(str(f)) + ;
" C(" + ltrim(str(nMaxColWidth)) + "), "
endfor
cFields = left(cFields, len(cFields) - 2)
create dbf (cOutFile) (&cFields)
= parse()
do while not feof(nHandle)
cString = fgets(nHandle)
= parse()
enddo
= fclose(nHandle)

procedure parse
nFieldNo = 1
do while nFieldNo <= nFields
nPos = at(cSeparator, cString)
cCol = "fld" + ltrim(str(nFieldNo))
&cCol = left(cString, nPos - 1)
cString = substr(cString, nPos + ;
iif(nFieldNo < nFields, 1, 0))
nFieldNo = nFieldNo + 1
enddo
insert into (cOutFile) from memvar[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top