Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

creating DBF file from text file

188 views
Skip to first unread message

happytoday

unread,
Aug 6, 2012, 5:45:06 AM8/6/12
to
Dear all,
I need to store pages delimited by FORMFEED character to Memo fields .
each record is indexed by unique key such account number .
Where can I find functions that deal with this matter ?

AnthonyL

unread,
Aug 6, 2012, 7:18:36 AM8/6/12
to
I'm a bit rusty now but isn't a simple matter of

append from xxx.txt delimited with chr(whatever formfeed is ~
chr(12)?)

Alternative progressively read the file picking out each block of text
between each occurence of the formfeed character.


--
AnthonyL

dlzc

unread,
Aug 6, 2012, 10:11:33 AM8/6/12
to
Dear happytoday:

On Monday, August 6, 2012 2:45:06 AM UTC-7, happytoday wrote:
...
> I need to store pages delimited by FORMFEED character

character 12.

> to Memo fields .

AnthonyL's method using "append from ... delimited with" is most elegant. This will generate one record for each page.

An alternative might be to simply append the entire file into the memo field (memoread()). That way you always have all pages, in order, and one record for the entire "report".

select <cMemoFileTableAlias>
append blank
replace AcctNo with Master->AcctNo
replace RprtName with <cFileName>
replace CaptureDt with date()
replace Body with memoread( <cFileName> )

> each record is indexed by unique key such
> account number .

David A. Smith

E. Fridman

unread,
Aug 6, 2012, 12:35:54 PM8/6/12
to
David,

>> to Memo fields .

> AnthonyL's method using "append from ... delimited with" is most elegant.
> This will generate one record for each page.

I believe that it's just a wishful thinking on your (and Anthony's) part.

APPEND FROM DELIMITED can't handle memo fields - it ignores them.

Delimiters pertain to character fields, fields still need to be separated by comas, and records need to be CR+LF terminated.

DELIMITED Text File Format Specifications
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
File Element Format
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Character fields May be delimited, with trailing blanks truncated
Date fields yyyymmdd
Logical fields T or F
Memo fields Ignored
Numeric fields Leading zeros may be truncated
Field separator Comma
Record separator Carriage return/linefeed
End of file marker 1A hex or CHR(26)


=========================================================

dlzc

unread,
Aug 6, 2012, 1:43:54 PM8/6/12
to
Dear E. Fridman:

On Monday, August 6, 2012 9:35:54 AM UTC-7, E. Fridman wrote:
>
> >> to Memo fields .
>
> > AnthonyL's method using "append from ...
> > delimited with" is most elegant.
>
> > This will generate one record for each page.
>
> I believe that it's just a wishful thinking on
> your (and Anthony's) part.
>
> APPEND FROM DELIMITED can't handle memo fields
> - it ignores them.
>
> Delimiters pertain to character fields, fields
> still need to be separated by comas, and records
> need to be CR+LF terminated.
...
> Memo fields Ignored

He posted in clipper, xharbour, and visual-objects newsgroups. Even in Clipper, you can specify which fields are being populated. Which *should* (in my personal fairy land) override the default of ignoring a memo field.

I should try this tonight in clipper and xharbour...

David A. Smith

pe...@nospam.demon.co.uk

unread,
Aug 7, 2012, 2:52:59 AM8/7/12
to
In article <867ea78a-57f9-49b9...@googlegroups.com>
DELIMITED WITH refers to the string delimiter (usually "), not the
field separator (which is a comma).

A long time ago I had the need to read a text file a line at a time
(variable length lines) and S'87 has no such function, so I wrote one.
(OK, you can read one char at a time looking for a CR or LF but that
is very inefficient.)

I include the source below -- all you need to do is to change the LF,
CHR(10), for FF, CHR(12), and the returned string should contain a
whole "page" of data. You can then MEMOWRITE() this. It would also
be sensible to change the 'linesize' default to something more
representative of a 'pagesize' and perhaps rewrite for Clipper 5.x.

-------- start code ---------
*
* freadln() - read a line of text from a file up to and including
* the LF delimiter
* params: handle: obtained from a previous call to fopen()
* linesize: the "ideal" or estimated line length of the
* file in question. This param is optional and defaults
* to 256 if not specified.
* Returns: CHARACTER; a line of text from the file or an empty
* string [""] on EOF or error. Use DOSERROR() to decide
* which.
* Notes: the ideal value for 'linesize' is slightly longer than
* the length of the majority of lines in the file, ideal
* in the sense of performance. The default value of 256
* ought to be OK for "most" text files.
*
* Usage: cTextLine = freadln (handle [,opt_line_length])
*

function freadln
parameters handle, linesize

private string
private lf
private nbytes

*-- S87 doesn't like this:
*-- if pcount() < 2 .or. linesize <= 0
*-- SO...
if pcount() < 2
linesize = 256
elseif linesize <= 0
linesize = 256
endif

string = space (linesize)
lf = chr(10)
nbytes = fread (handle, @string, linesize)

if nbytes <= 0
return ""
endif

pos = at (lf, string)
if pos == 0
return string + freadln (handle, linesize)
else
string = substr (string, 1, pos)
fseek (handle, pos - nbytes, 1)
endif

return string

-------- end code ---------

Just trying to help,
Pete
--
Believe those who are seeking the truth.
Doubt those who find it. - Andr� Gide

AnthonyL

unread,
Aug 7, 2012, 7:44:50 AM8/7/12
to
On Tue, 07 Aug 2012 06:52:59 +0000 (UTC), pe...@nospam.demon.co.uk
wrote:
The company I worked for wrote a lot of Clipper software and we quite
regularly had needs to read text files. I left the clever stuff to
our programmers and they did a lot of text manipulation. Efficiency
of processing for a one-off operation may not be important. I've
certainly used a decent text editor to do an initial find & replace
control characters so it wouldn't be that hard to set up appropriate
delimiters. The OP wants each FF separated item as a separate record
and there are several ways to acheive this. Having been through all
the versions of Clipper (having started with dBASE) and having created
quite a library of functions I am sure that your suggestion is one
that was used when appropriate.


--
AnthonyL

dlzc

unread,
Aug 7, 2012, 11:35:20 AM8/7/12
to
Dear Pete:

On Monday, August 6, 2012 11:52:59 PM UTC-7, (unknown) wrote:
> In article <867ea78a-57f9-49b9-9fc6-ea926257c***@googlegroups.com>
>
> dl***@cox.net "dlzc" writes:
...
> > He posted in clipper, xharbour, and visual-objects
> > newsgroups. Even in Clipper, you can specify which
> > fields are being populated. Which *should* (in my
> > personal fairy land) override the default of
> > ignoring a memo field.
>
> > I should try this tonight in clipper and xharbour...

I failed to try this last night. I do suspect the "elegant" method will fail in Clipper, but might not in (x)Harbour, since you could set() the EOL characters to chr(12) (hopefully remembering to set them back before doing other things). Which makes the method less elegant.

...
> DELIMITED WITH refers to the string delimiter
> (usually "), not the field separator (which is
> a comma).

Agreed. Additionally, the End Of Line marker cannot be changed in Clipper.

...
> Just trying to help,

And I always appreciate that. Thank you.

David A. Smith
0 new messages