Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Data from tab delimited file to a cursor
Message
From
28/10/2003 15:44:25
 
 
To
28/10/2003 14:17:16
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00843661
Message ID:
00843763
Views:
25
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 )

   *  Create the fields specification of the SQL-Select string
   IF lnFieldCount > 0

      FOR lnI = 1 TO lnFieldCount

         lcSelString = "SPACE( 100 ) AS field" + TRANSFORM( lnI ) + "," 

      NEXT

      *  Finish creation of the SQL-Select string
      lcSelString = "SELECT " + lcSelString + " FROM xxTable INTO CURSOR myCursor"

      *  Execute the SQL-Select
      &lcSelString

      IF _TALLY > 0

         SELECT myCursor
         
         *   Append the data into the new cursor.
         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.com

No trees were destroyed in sending this message. However, a large number of electrons were diverted from their ordinary activities and terribly inconvenienced.
Previous
Reply
Map
View

Click here to load this message in the networking platform