Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Appending from a textfile
Message
From
28/10/1999 05:41:44
 
 
To
28/10/1999 01:06:09
Jeffrey Score
Dept of Defense (Usmc)
Iwakuni, Japan
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00282827
Message ID:
00282861
Views:
20
>Once again I have a problem that is probably very simple and I am just not getting it.
>
>I have a textfile that I want to append into a database. The problem is that every record is 2 lines on the report. I cannot figure out how(if) I can get foxpro to append the data I need from both lines.
>
>The text file is standard ASCII and has no tabs or carraige returns on it.
>

You can read the file using VFP's low-level file I/O and add the data to the table in the correct fields. It's not a one line command, but it should do what you need to do. I deal with this all the time in my applications, where I'll often have to import a file sent from a mainframe. A short example from some code I use to import fixed-length data from a file from a mainframe:
lc_root = '\\Server1\ImpData\'
lc_file = lc_root+'rawdata\file1.'
lc_dbf  = lc_root+'rawdbf\rd_zpair.dbf'

ln_fh = fopen(lc_file)  && open the file from mainframe for input

create table (lc_dbf) FREE ( origzip    C(3), ;
                         destzip    C(3), ;
                         scalenum   c(6), ;
                         MinChgUnd  I, ;
                         MinChgOvr  I, ;
                         L5CRate    I, ;
                         M5CRate    I, ;
                         M1MRate    I, ;
                         M10MRate   I, ;
                         M40MRate   I )
USE

use (lc_dbf) ALIAS File1   && open the output table we created above

do while ! feof(ln_fh)

   *  read 97 characters from the file from the mainframe

   lc_linebuf = fread(ln_fh,97)

   *  and then add a record to File1 using parts of the record read

   insert into File1 VALUES ( SUBSTR(lc_linebuf,2,3), ;
                              SUBSTR(lc_linebuf,8,3), ;
                              PADL(TRIM(SUBSTR(lc_linebuf,20,5)),6,'0'), ;
                              VAL(SUBSTR(lc_linebuf,27,6)), ;
                              VAL(SUBSTR(lc_linebuf,34,6)), ;
                              VAL(SUBSTR(lc_linebuf,41,6)), ;
                              VAL(SUBSTR(lc_linebuf,48,6)), ;
                              VAL(SUBSTR(lc_linebuf,55,6)), ;
                              VAL(SUBSTR(lc_linebuf,76,6)), ;
                              VAL(SUBSTR(lc_linebuf,90,6)) )
enddo                         
=fclose(ln_fh)
USE IN File1
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform