Joe,
OK, as Tracy Holzer suggested in another post on this thread, your fields are probably delimited with a CHR( 10 ). Otherwise the Excel spreadsheet would not format correctly.
Creating a cursor with an unknown number of fields is a multi-step process. First we get the data from the text file an array with ALINES(). Then we get the number of columns in the resulting array -- this gives us a count of the number of fields to include in the cursor. Create the cursor using SELECT-SQL, and finally append the data into the blank cursor using the APPEND command.
This is not intended to be finished code, so test it thoroughly. MyText.txt is the text file with the data to be appended. MyCursor is the cursor into which the data will be appended. There are quite a lot of ways to kill this horse, so someone else may have a much better idea.
LOCAL laLines[ 1 ], lnRecCount, lcSelString, lcText
lcText = FILETOSTR( mytext.txt )
lnRecCount = ALINES( laLines, lcText )
lcSelString = ""
IF lnRecCount > 0
lnFieldCount = ALEN( laLines, 2 )
IF lnFieldCount > 0
FOR lnI = 1 TO lnFieldCount
lcSelString = "SPACE( 100 ) AS field" + TRANSFORM( lnI ) + ","
NEXT
lcSelString = "SELECT " + lcSelString + " FROM xxTable INTO CURSOR myCursor"
&lcSelString
IF _TALLY > 0
SELECT myCursor
APPEND FROM myText.txt DELIMITED
ENDIF
ENDIF
ENDIF
RETURN
One caveat using ALINES() in Ver 7.0. There is a bug that may result in a c000005 error under certain circumstances. See thread 824830 for the problem and a fix.
Regards,
Jim Edgar
Jurix Data Corporation
jmedgar@yahoo.comNo trees were destroyed in sending this message. However, a large number of electrons were diverted from their ordinary activities and terribly inconvenienced.