Groups > dBase > dBase Knowledge base > Re: Appending a .CSV file




Appending a .CSV file

Appending a .CSV file
Fri, 23 Feb 2007 14:52:39 -050
Hi all,

I have to import then append a .csv file into dbase 5.7. I know I did this 
prior to this version and did not have a problem but have encountered one 
and wanted to know if anyone else has.

The import works fine(although I notice that the headers are not there as 
they are in a text comma delimited file)but when I append(append from 
webcsv.txt delimited) it only appends the first record and not the rest.

Does anyone know why and how to correct this?

Thanks,Lorna

Post Reply
Re: Appending a .CSV file
Fri, 23 Feb 2007 22:02:23 -080
There must be a strange charactor at the end of the first line and possibly 
all lines.  If your lucky and it is only on the first line you can just 
eliminate the first like and try the import again.
If it goes beyond that then you will end up having to read the file in using 
the low level functions or, even better yet, there is an Import Utility in 
the DUFLP that reads in the file line by line.  It might do the trick for 
you.

A little trick you might already know, when I have to read a comma delimited 
file in, I use the following to parse each line, it simplifies your task.

Some data to use for the below sample:
"9","042535957","Lilly, Everett","17733
Miranda 
St","Encino","CA","91316-1114"
aRow = {"9","042535957","Lilly,
Everett","17733 Miranda 
St","Encino","CA","91316-1114"}
Now aRow will be an array with each field in one element and you can scan it 
with a for statement.

Example:
//-------------start of code ---------------------
oFile = new file()
oFile.open("xyz.txt")
do while not oFile.eof()
   cLine = oFile.gets(10000, chr(13)+chr(10))
   // now the end of line charactor might need to be discovered but in most 
cases it is chr(13)+chr(10).
   cLine = "{"+cLine+"}"
   aRow = &cLine
   for i = 1 to aRow.size
      ?arow[i]
     //replace field1 with aRow[i], field2 with aRow[i], field3 with aRow[i]
   endfor
enddo
return
//-----------------end of code------------------
Untested and made up on the fly so, use with caution.

If the end of line char is different you might try using chr(10) by itself 
or chr(13) by itself

Give that a try and let us know if you need more help.

HTH

Greg Hill



"lorna walsh" <lwalsh@necc.mass.edu> wrote in message 
news:y5KJNY4VHHA.1988@news-server...
> Hi all,
>
> I have to import then append a .csv file into dbase 5.7. I know I did this

> prior to this version and did not have a problem but have encountered one 
> and wanted to know if anyone else has.
>
> The import works fine(although I notice that the headers are not there as 
> they are in a text comma delimited file)but when I append(append from 
> webcsv.txt delimited) it only appends the first record and not the rest.
>
> Does anyone know why and how to correct this?
>
> Thanks,Lorna
> 

Post Reply
Re: Appending a .CSV file
Sat, 24 Feb 2007 15:58:38 -080
"lorna walsh" <lwalsh@necc.mass.edu> wrote in message 
news:EmB404FWHHA.1796@news-server...
> It would seem that the last entry in the first line for some reason is in 
> double quotes and is stoping the rest from downloading.  When I take out 
> those quotes it works fine.
>
> Will the below program work to do that?  I'm using the 5.7 version.
> Also, I have unziped the DUFLP but do not see the Import Utility.
>
> Thanks for your help,Greg


Can you post the first, say 5 rows from that text file?

I believe 5.7 had the file() class if not I will post the code using the 
functions.

With a little adjustment you can try the code I gave you, but I left out a 
couple things 1) in the start of the program you will need to open the table 
that will be appended to, 2) put "APPEND BLANK"  on the line right
above the 
replace field1 with aRow[i].

Also make sure you have the most recent duflp files.

With the above I am sure we can resolve the issue.

Greg Hill

Post Reply
Re: Appending a .CSV file
Sat, 24 Feb 2007 16:39:56 -050
It would seem that the last entry in the first line for some reason is in 
double quotes and is stoping the rest from downloading.  When I take out 
those quotes it works fine.

Will the below program work to do that?  I'm using the 5.7 version.
Also, I have unziped the DUFLP but do not see the Import Utility.

Thanks for your help,Greg
Lorna;)

"Greg Hill" <ghill123@hotmail.com> wrote in message 
news:ero2qi.g4.1@news.alldbase.com...
> There must be a strange charactor at the end of the first line and 
> possibly all lines.  If your lucky and it is only on the first line you 
> can just eliminate the first like and try the import again.
> If it goes beyond that then you will end up having to read the file in 
> using the low level functions or, even better yet, there is an Import 
> Utility in the DUFLP that reads in the file line by line.  It might do the

> trick for you.
>
> A little trick you might already know, when I have to read a comma 
> delimited file in, I use the following to parse each line, it simplifies 
> your task.
>
> Some data to use for the below sample:
> "9","042535957","Lilly, Everett","17733
Miranda 
> St","Encino","CA","91316-1114"
> aRow = {"9","042535957","Lilly,
Everett","17733 Miranda 
> St","Encino","CA","91316-1114"}
> Now aRow will be an array with each field in one element and you can scan 
> it with a for statement.
>
> Example:
> //-------------start of code ---------------------
> oFile = new file()
> oFile.open("xyz.txt")
> do while not oFile.eof()
>   cLine = oFile.gets(10000, chr(13)+chr(10))
>   // now the end of line charactor might need to be discovered but in most

> cases it is chr(13)+chr(10).
>   cLine = "{"+cLine+"}"
>   aRow = &cLine
>   for i = 1 to aRow.size
>      ?arow[i]
>     //replace field1 with aRow[i], field2 with aRow[i], field3 with 
> aRow[i]
>   endfor
> enddo
> return
> //-----------------end of code------------------
> Untested and made up on the fly so, use with caution.
>
> If the end of line char is different you might try using chr(10) by itself

> or chr(13) by itself
>
> Give that a try and let us know if you need more help.
>
> HTH
>
> Greg Hill
>
>
>
> "lorna walsh" <lwalsh@necc.mass.edu> wrote in message 
> news:y5KJNY4VHHA.1988@news-server...
>> Hi all,
>>
>> I have to import then append a .csv file into dbase 5.7. I know I did 
>> this prior to this version and did not have a problem but have 
>> encountered one and wanted to know if anyone else has.
>>
>> The import works fine(although I notice that the headers are not there
as 
>> they are in a text comma delimited file)but when I append(append from 
>> webcsv.txt delimited) it only appends the first record and not the
rest.
>>
>> Does anyone know why and how to correct this?
>>
>> Thanks,Lorna
>>
>
> 

Post Reply
Re: Appending a .CSV file
Sun, 25 Feb 2007 01:11:46 -080
"Geoff Wass [dBVIPS]" <gswassREMOVE_ME@attglobal.net> wrote in
message 
news:MPG.204afe2fd3ec40e69897f2@news.dbase.com...
> In article <erq1sq.2b8.1@news.alldbase.com>, ghill123@hotmail.com
> says...
>> "lorna walsh" <lwalsh@necc.mass.edu> wrote in message
>> news:EmB404FWHHA.1796@news-server...
>> > It would seem that the last entry in the first line for some
reason is 
>> > in
>> > double quotes and is stoping the rest from downloading.  When I
take 
>> > out
>> > those quotes it works fine.
>> >
>> > Will the below program work to do that?  I'm using the 5.7
version.
>> > Also, I have unziped the DUFLP but do not see the Import Utility.
>> >
>> > Thanks for your help,Greg
>>
>>
>> Can you post the first, say 5 rows from that text file?
>>
>> I believe 5.7 had the file() class if not I will post the code using
the
>> functions.
>>
>> With a little adjustment you can try the code I gave you, but I left
out 
>> a
>> couple things 1) in the start of the program you will need to open the

>> table
>> that will be appended to, 2) put "APPEND BLANK"  on the line
right above 
>> the
>> replace field1 with aRow[i].
>>
>> Also make sure you have the most recent duflp files.
>>
>> With the above I am sure we can resolve the issue.
>>
>> Greg Hill
>
>
> Greg,
>
> FILE() objects came with the 32-bit Visual dBASE 7.01 (etc.) It is not
> in the 16-bit VdB 5.x.
>
> When fetching the dUFLP, be aware there is a 32-bit version for products
> VdB 7 throught dB+ and a 16-bit version of dBASE III, IV and VdB 5.x.
> Some code in the 32-bit version works with VdB 5.x, but definitely not
> all of it.

Thanks Geoff, I was not sure about it.


Post Reply
<< Previous 1 2 3 4 5 6 7 Next >>
( Page 1 of 7 )
about | contact