Subject Re: character string problem
From Mervyn Bick <invalid@invalid.invald>
Date Sun, 17 Mar 2019 09:43:21 +0200
Newsgroups dbase.getting-started
Attachment(s) create_tmaster_csv.prg

On 2019-03-17 7:49 AM, Mervyn Bick wrote:
> On 2019-03-17 12:05 AM, Charlie wrote:
>> OK back to the drawing board...
>>
>> Does not like line 4905.  but 4904 is OK.... Not sure what is going on
>> here!!!
>
> I don't have the same line numbers here.  Which line is giving a problem?

Instead of creating tmaster.dbf and then adding blank records which need
to be populated one by one you can use APPEND FROM master to do the same
job in one line.  This will immediately remove a lot of "clutter" from
your code.

Try the attached program and let's see how far we get.


Mervyn.



if file('tmaster.csv')
   new file().delete('tmaster.csv')
endif

if file('tmaster.dbf')
  drop table tmaster
endif

create table tmaster (;
id numeric(11), ;
part_no char(10), ;
title char(35), ;
qty numeric(6,0), ;
sell numeric(7), ;
grade char(16), ;
mfg char(35), ;
cuml numeric(5,0), ;
sdate date, ;
asell numeric(7), ;
au_desc char(254))

use tmaster
append from master for asell # 0 and title # null and part_no < "AF00760X"
scan
  replace part_no with escape_quote(part_no)
  replace au_desc with escape_quote(au_desc)
  replace id with recno()
endscan
go bottom
msgbox( "Count is " +id+ ".  The master.csv file must be ftped to the correct directory before importing into mysql." )
copy to tmaster.csv delim
use

cFileIn ='tmaster.csv'
cFileOut = 'tempworkfile.txt'
fIn = new file()
fIn.open(cFileIn)
fOut = new file()
fOut.create(cFileOut)
do while not fIn.eof()
   cRead = fIn.gets()
   If  not chr(26)$cRead
      fOut.Puts(cRead)
   endif
enddo
fIn.close()
fOut.close()
new file().delete(cFileIn)
new file().rename(cFileOut,cFileIn)


function escape_quote(cStr)
   for n = len(cStr) to 1 step -1
      if substr(cStr,n,1) = ["]
         cStr = stuff(cStr,n,1,[\"])
      endif
   next
   return cStr