Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Vfp50 - import from a text file into vfp
Message
De
11/07/1997 11:02:26
 
 
À
09/07/1997 15:26:01
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00038828
Message ID:
00039468
Vues:
46
>> are you using APPEND
>> FROM to post to the vfp dbf file? I want to move a text file (using a low
>> level file
>> functions) to a vfp dbf file. Could you show me some code?..thanks
>> again..rob
>
>Using Append From is much, much faster, only if it's possible :)
>That is if the text file is falling into some of available formats (SDF,
>tab delimited, comma delimited, anything delimited). Doing it with LL
>functions is a bit of a PITA but is mostly unavoidable if you have to
>deal with foreign data formats. I used that approach for converting MBP
>(and other) Cobol data, even when the original table was fixed-length
>and cr-ended (that is, SDF) because some of the fields contained null
>bytes, in which case the columns to the right were read as blanks, no
>matter if only one was blank.
>
>The general approach is to read a portion of a source file into a string
>buffer (recognizing the EOL is a story for itself, and won't work if the
>line contains nulls), then chopping the string into substrings,
>converting the cutouts to proper data types (like converting as mmddyy
>string into a date variable, or storing a val(chop)/100 into a
>m.numeric_var), and then Insert Into DestTable From Memvar, and so on
>While Not Feof(source_handle), and =fclose(source_handle) after that.
>
>The best part of the story depends on the data you are reading - what
>were they written with, what's the format, what's the delimiters and so
>on. It may be a good experience to do it once in a while, but I strongly
>recommend to Append From, if possible.

Hi Dragan... thanks for your answer.. I got the below code
from my friend JP on the UT...When you can not use APPEND FROM...
try this....rob


PARAMETERS lcTapeFile
** This Procedure Reads a fixed length ASCII file using low-level file functions
** And INSERTS the data into a DBF
** Note: The files have been loaded to disk via 9-Track Tape transport

lnBCnt = 0
IF FILE(lcTapeFile)
lnHand = fOpen(lcTapeFile) && Open the Text File
IF lnHand <= 0
CLEAR
WAIT WINDOW "Error Opening Tape File!"
RETURN
ENDIF
ELSE
CLEAR
WAIT WINDOW "Error Tape File not found!"
RETURN
ENDIF
lcBuff = SPACE(7300) && The record length is 730 so we read 10 recs at a time
DO WHILE .T.
lnBuff = FREAD(lnhand,@lcBuff,7300) && read in 10*730 byte records
lnOffSet = 0
IF lnBuff < 730 && If we read less that 730, we must be done
EXIT
ENDIF
DO WHILE lnBuff > 0
IF lnBuff < 730
EXIT
ENDIF
** Initialize all fields
m.lcCo = SUBSTR(lcBuff,lnOffSet+1,2)
m.cssn = SUBSTR(lcBuff,lnOffSet+4,9)
m.cssfx = SUBSTR(lcBuff,lnOffSet+13,1)
m.clast = SUBSTR(lcBuff,lnOffSet+24,20)
m.cfirst = SUBSTR(lcBuff,lnOffSet+44,15)
INSERT INTO DBFFILE FROM MEMVAR
lnBuff = lnBuff - 730 && Pick off 730 bytes at a time
lnOffset = lnOffset + 730 && Offset increases to 7300 then cycles
ENDDO && while there are bytes in the record buffer
ENDDO && while there are bytes in the file

fClose(lcTapeFile) && we are done
RETURN
Robert Keith
Independent Developer
San Antonio, Texas
E-mail address:
rebelrob1@yahoo.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform