Subject Re: Possible Corrupted Table
From Mervyn Bick <invalid@invalid.invald>
Date Fri, 12 Jul 2019 08:20:30 +0200
Newsgroups dbase.getting-started
Attachment(s) replace_lf_with_crlf.prg

On 2019-07-12 3:13 AM, Ruth Bromer wrote:
> I have a program that reads in a .csv file and populates a table.  It's
> been working just fine, and now that I want to load real data into it,
> the program blew up.  It didn't like the append command.  It said that
> the table is corrupted and all that is left is the header. Well, the
> command before emptied the table so of course noting is in it.
>
> I'm sure that I did something wrong but I can't figure out what that
> might be.

This time when the .csv file was created it was created with line feed
characters as the end of record markers.  This is the format used by
UNIX.  Windows wants carriage return, line feed as the end of record
marker.  The person creating the .csv file just needs to remember to set
the appropriate switch. :-)

All is, however, not lost.  The attached program will replace line feed
characters that don't have a preceding carriage return with CRLF.  If
the file already has CRLF end of record markers no action will be taken.

Mervyn.




clear
CR = chr(13)
LF = chr(10)
CRLF = CR+LF
nCount = 0
new File( ).copy( "competitor.csv", "competitor_lf.csv" )
fIn = new file()
fIn.open('competitor_lf.csv')
fOut = new file()
fOut.create('competitor.csv')
cRead1 = fIn.read(1)
fOut.write(cRead1)
do while not fIn.eof()
  cRead2 = fIn.read(1)
  if cRead2 = chr(10) and cRead1 <> chr(13)
     fOut.write(CRLF)
   else
     fOut.write(cRead2)
   endif
   cRead1 = cRead2
   nCount ++
   If nCount%300 = 0
     ?? '*'
   endif  
enddo
?
fIn.close()
fOut.close()
new File().delete('competitor_lf.csv')