Subject Re: Automated DBF export to CSV
From Mervyn Bick <invalid@invalid.invalid>
Date Thu, 21 Sep 2017 09:44:57 +0200
Newsgroups dbase.getting-started

On 2017-09-20 10:35 PM, Tom McDermott wrote:
> I am requesting assistance in automating an extract from a DBF file in dBase plus 2.8 to a CSV file.
>
> I have never used dBase before, but I have dBase plus 2.8 installed and can connect to the DBF file.  I can also manually extract to a CSV file using the Data Module wizard. Since I need this on a daily basis, I have to automate a process.  I am running windows 7 enterprise
>
> Do I create an executable and then schedule it to run?
> Any help or references are greatly appreciated.
> Thank you.
>

Creating an executable file and setting Windows to run it on schedule is
the last, and perhaps easiest, bit of the problem to solve.  As Isabella
Beeton is reputed to have written in her cookbook, "To make rabbit stew,
first catch your rabbit.". :-)

dBASE has the built-in ability to copy a .dbf file to a .csv file that
is very simple to use.

    use whatever.dbf
    copy to whatever.csv delimited
    use

The problem with this is that it doesn't include any memo fields in the
.csv file and dates in the .csv file are written as ... ,yyyymmdd, ...
i.e no delimiters and no separators.  This date format in a .csv file is
acceptable to other dBASE applications but may cause problems for
3rd-party applications, such as Excel, which won't recognise it as a date.

If you don't need to deal with memo fields and the yyyymmdd date format
is acceptable building an executable file will be a very simple matter
indeed.

Life gets a bit more complicated if you want to run the executable on a
different computer as you then need to install the dBASE runtime
executable and the BDE (Borland Database Engine) on the computer a well.

There is code in the dUFLP (dBASE Users Function Library Project) which
does include memo fields in the output but there is no provision for
changing the date format for the .csv file.

Although it may be a case of reinventing the wheel, going the DIY route
and writing your own code to create a .csv file is fairly
straightforward and if you do this you can put anything you want into
the .csv file.

If your input and output files are not in the same folder you will
either need to hard-code paths into your code or delve into the BDE
Administrator to create database aliases as, as far as I can remember,
dBASE 2.8 doesn't have the ability to create these in the program.  If
you hard-code paths the program will need to be edited and the
executable file rebuilt if you ever want to use other folders.

Does the input file use the same name every day or is the date perhaps
included in the name?

Do you want a separate output file each day, again possibly with the
date included in the name, or do you want to append each day's data to
the existing file?

Is the date form yyyymmdd acceptable in the .csv file or do you require
something else?

Delimiters for character fields are only really necessary where there is
the possibility of a comma in the text.  If you are certain that there
will NEVER be a comma in any of the character fields (and the receiving
application can handle un-delimitted character fields) the delimiters
can be dispensed with which will simplify the coding a bit.

Does the .dbf file include a _dbaselock field?  This will be the last
field in a record and normally needs to be excluded from the .csv file.

Do you want the fieldnames included as the first record of the .csv file?

Mervyn.