I have a small C program I wrote in 1998 that converts DBF to Fixed Field ASCII (excluding DBFs with DBTs). If you know the number of columns in the DBF you can calculate the DBF header length ((Columns * 32) + 32) and if you know the length of the RECORD it will convert OK.

At the time it was all I needed, so I didn't try to totally automate it to get the information from the File Header (all the above can be determined from the header) so it would be a matter of SOURCEFILE to OUTPUTFILE.

Having said all that, If anyone would find the converter of use, I have the EXE available. If you have a c or c++ compiler here is the source:

/* begin source */
/* DBF to Fixed Field ASCII mbyerley 032898 */

#include <stdio.h> /* file i/o */
#include <stdlib.h> /* for exit(0) */
#include <string.h>
#include <conio.h>
#define MXFILEN 45
#define MXNAMLEN 8
#define MXFAMEM 4

void main()
{

/* variables */

char infil[MXFILEN];
char outfil[MXFILEN];
char *s1;
char *s2;
char *s3;
char *s4;

int i;
int c;
int nr;
int hl;
int rl;


FILE *fpi,*fpo; /* = fopen(infil,"r") fopen(outfil,"r") */

 /* prompt for file name */
s1 = "Enter Input file name     ";
s2 = "Enter Output file name    ";
s3 = "Enter Input File Header Length     ";
s4 = "Enter Input File Record Length     ";


printf("%s\n",s1);
scanf("%s",&infil);
  fpi = fopen(infil,"r");
  if (fpi == NULL)
  {
  printf("Error Opening Input File");
  exit(0);
  }
  printf("Input File %s Open / Read Only\n",infil);

  printf("%s\n",s2);
scanf("%s",&outfil);
  fpo = fopen(outfil,"w+");
  if (fpo == NULL)
  {
  printf("Error Opening Output File");
  exit(0);
  }
  printf("Output File %s Opened \n",outfil);
hl = 0;
printf("%s\n",s3);
scanf("%d",&hl);

rl = 0;
printf("%s\n",s4);
scanf("%d",&rl);
  if (rl == NULL)
  {
  printf("Record Length Cannot Be Null");
  exit(0);
  }

printf("Header Length is set to %d \n", hl);
printf("Record Length is set to %d \n", rl);
printf ("\n \n Process File As Specified \n");
char chr;
do {
 chr = getch();
 }
while ((chr != 'Y' && chr != 'y' && chr != 'N' && chr != 'n' && chr != 27));

  if (fpi != NULL && (chr == 'Y' || chr == 'y'))
   {

   for ( i = 0; i != hl; ++i)
   getc(fpi);

    for (i = 0, nr = 0; (c = getc(fpi)) != EOF; ++i)
   {
     if (i == rl)
    {
    putc(13, fpo);
    putc(10, fpo);
    //putc('/n', fpo);
    i = 0;
    ++nr;
    }
              putc(c, fpo);
   }
   printf("Number of Records is %d",nr);
   }


 fclose(fpi);
 fclose(fpo);
 exit(0);
/* end source */



----- Original Message ----- From: "Dennis McGrath" <[email protected]>
To: "RBASE-L Mailing List" <[email protected]>
Sent: Wednesday, September 15, 2010 9:01 AM
Subject: [RBASE-L] - Re: Problems attaching DBase table


Is the DBF in the current directory or elsewhere?

Perhaps, instead, you could try setting up an ODBC connection to the table and go through that.

Dennis

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Mike Byerley
Sent: Tuesday, September 14, 2010 6:40 PM
To: RBASE-L Mailing List
Subject: [RBASE-L] - Re: Problems attaching DBase table

Here found the identifiers:

DBF FILE STRUCTURE
~~~~~~~~~~~~~~~~~~

BYTES   DESCRIPTION
00 FoxBase+, FoxPro, dBaseIII+, dBaseIV, no memo - 0x03
FoxBase+, dBaseIII+ with memo - 0x83
FoxPro with memo - 0xF5
dBaseIV with memo - 0x8B
dBaseIV with SQL Table - 0x8E



----- Original Message ----- From: "Hans Manhave" <[email protected]>
To: "RBASE-L Mailing List" <[email protected]>
Sent: Tuesday, September 14, 2010 6:23 PM
Subject: [RBASE-L] - Re: Problems attaching DBase table


Yes, that gives no errors, lists the table in my R:Base tables list.  It
also did not give the reserved words error.

The error that I now get is #2585, Cannot find dBase file in current
directory or path.  It just attached the file, how can it have a path
error?  This occurs when I want to open the table.  I probably shouldn't
be opening the table?  Creating a form based on the table does work.
However, using that form creates the same error.





-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of
[email protected]
Sent: Tuesday, September 14, 2010 5:06 PM
To: RBASE-L Mailing List
Subject: [RBASE-L] - Re: Problems attaching DBase table

Hans:  if you type "SET ANSI OFF" before attaching, does that help any?

Karen




I end up with a "R:Base eXtreme 9.0 (64) has encountered a
problem and
needs to close" error and Windows wants to call home.

Following is my process (using R:Base eXtreme 9.0 (64) with the
latest
updates installed):

- Connect a R:Base 9 database
- Attach a DBF table, no index
- receive error msgs that reserved words are being used and I
update
each of those when it pops up with an acceptable field name.
When it is
through, it comes up with the Microsoft problem.

What am I not understanding that is creating this error?

I am not using an index, yet, just wanting to open the DBF
table.  This
problem exists if I want to open a 52MB table or a 1KB table.  I
keep
getting the Windows error message and R:Base crashes/terminates.
R:Base
opened the file or it wouldn't have known about the reserved
word usage
for the column names.

Thoughts, please?

Thanks,

Hans Manhave


Reply via email to