Subject Re: IMPORTING CSV file
From Mervyn Bick <invalid@invalid.invald>
Date Thu, 11 Apr 2019 10:35:22 +0200
Newsgroups dbase.getting-started

On 2019-04-11 8:02 AM, Lee Grant wrote:
> Adding to that,
>
> Since I needed to do what I said, I went ahead and created a small
> program that just encloses the csv data in quotes so they can manually
> append the file to a table they have to format the same way the file
> presents the data, in character strings, so things like the periods,
> percentage sign and other characters, other than the comma's and the
> CR/LF can be brought in as is. They can do conversions once the raw data
> has been imported. *WARNING* this is just a sample program and WILL
> delete the converted .csv file if you run it again and create it
> again...plus you need to rename or copy the file you want converted to
> the "Test.csv" name...sloppy, but I was just making sure it did what I
> wanted it to do. :)

I appreciate that the program was written as a practice exercise but you
shouldn't need the program at all.  If you append a .csv file containing
mixed field types into a table with only character fields the contents
of all fields will be saved as characters.

If the originating program has not included delimiters in a .csv file
there is no reliable way of adding them if the contents of a text field
contains one or more commas.  A further complication is that in Europe
many countries use a comma as the decimal point.  This can cause chaos
if one tries to use .csv files.  In this case a tab separated file is a
better option.  dBASE has no built-in method for creating these files.

If the are any delimiters in the .csv file your little program will
result in the delimiters being included in the table when the .csv file
is imported.

Delimiters around the contents of characters fields are only needed if
the contents contains a comma.  The delimiters enable the reading
program to recognise a comma in the field as text rather than accepting
it as a separator between fields.  In fact Excel, and probably other
programs, will only add the delimiters if there is a comma in a specific
cell.  Any .csv file created by Excel can, therefore, have delimiters
for a field in some records and not in others.  dBASE has no problem
dealing with this although, when creating .csv files, dBASE always adds
the delimiters whether they are necessary or not.

Redundant code in a program does no harm and it can help to jog one's
memory as to why a particular construct was adopted.  On the other hand
a little comment will serve just as well. :-)


//if fOut.exists(cConv)
//   fOut.delete(cConv)
//endif
fOut.create(cConv, "W") //Will overwrite existing file without warning


Mervyn.