Page 1 of 1

Alternative way of appending content to a file

Posted: Wed Mar 02, 2016 1:39 am
by Andy Edward
Hi,

I'm generating an HTML file (for reports) which I don't really know how big it will be.

Currently I'm using MEMOWRITE like so, which will write to the file for every record

Code: Select all

1st way
***********
DO WHILE !EOF()
     xCONTENT = "Some content that is based on the current record"
     EXPTEXT=MEMOREAD(xHTMLFILE)+XCONTENT   && 20160302
     MEMOWRITE(xHTMLFILE,EXPTEXT)            && 20160302
SKIP 
ENDDO
I understand that this way is non optimal as when the XHTMLFILE becomes too big (10MB-100MB), then the whole process of reading (MEMOREAD) and writing back will degrade speed wise.

I can always do something like this

Code: Select all

2nd way
***********
DO WHILE !EOF()
     xCONTENT += "Some content that is based on the current record"
SKIP 
ENDDO

EXPTEXT=MEMOREAD(xHTMLFILE)+XCONTENT   && 20160302
MEMOWRITE(xHTMLFILE,EXPTEXT)            && 20160302
but I don't know how much data xCONTENT variable will be able to store.

So my questions are:
For the 1st way, is there a function in xBase that will append the file instead of needing to read the file, append, and then write it back?

For the 2nd way, how much data can a variable hold? as the data size is unknown and might grow larger along the years. And I'm talking about 10MB-100MB

Any help is appreciated.

Regards,

Andy

Re: Alternative way of appending content to a file

Posted: Wed Mar 02, 2016 11:58 am
by Wolfgang Ciriack
Look at the function StrFile(), f.e.

Code: Select all

strfile(EXPTEXT,xHTMLFILE,.T.)
appends to the existing file xHTMLFile.

Re: Alternative way of appending content to a file

Posted: Wed Mar 02, 2016 9:48 pm
by Andy Edward
Wolfgang Ciriack wrote:Look at the function StrFile(), f.e.

Code: Select all

strfile(EXPTEXT,xHTMLFILE,.T.)
appends to the existing file xHTMLFile.
Thank you very much!

Regards,

Andy