Simplicty and flexibility!

MemoWriteToFile(),MemoReadFromFile(),MemoStringFrom(), MemoStringBetween() sample

Started by DataEase
You will need to Sign In to be able to comment on the Blog!

MemoWriteToFile(),MemoReadFromFile(),MemoStringFrom(), MemoStringBetween() sample

Download Sample

Seeing is believing, so please find attached a sample that showcase what you are looking for.

In this sample we write the content of a table with HTMLdocuments and strucured info to a document pr. record, then we read it back into another table and finally we process the memo and insert the results into a third table so it is exactly the same as the original.

Quite meaningless and a simple export/import would be much easier...but we are trying to show the flexibility and possibilities in combining all these functions.

Have a look and enjoy.

1. DocumentGenerator.

define "retval" text .

define "filename" text 200 .

for DocumentGenerator ;

filename := concat(GetCurrent("AppPath"),"\docs\",DocID,".txt") . -- generate filename

retval := WriteToFile(concat("DocID: ",DocID," /DocID"),filename,1) .-- write the value of DocID with enclosing tags.

retval := WriteToFile(concat("Date: ", Date," /Date"),filename,4) . -- same for date.

retval := WriteToFile(concat("CustomerName: ", CustomerName," /CustomerName"),filename,4) . etc..

retval := WriteToFile(concat("Heading: ", Heading,"/Heading"),filename,4) . etc.

retval := WriteToFile("Body: ",filename,4) .-- here we add the tag for body start.

retval := MemoWriteToFile(Body,filename,4) . --append body to file.


retval := ExecDQL("Delete records in DocumentReadback . delete records in DocumentProcessed. ") . -- just clean up the app.

retval := DocumentOpen("DocumentReadback") . -- open the next document in the chain.

2. Documentreadback

define "retval" text .

define "fileNr" numeric string 5 .

define "filename" text 200 .

fileNr := data-entry field1 .

while FileNr <=data-entry field2 do

filename := concat(GetCurrent("AppPath"),"\docs\",FileNr,".txt") .

if FileExists(FileName)=1 then -- check if the file exists, if it does we continue

enter a record in DocumentReadback -- create a new entry in DocumentReadback

dummy := MemoReadFromFile(Body,filename,1) . -- simpy reads the contents of the text file into the memo


FileNr := FileNr + 1 .


retval := RecordFirst() . -- show the first record we have read back.

3. Process the data we have read and insert them into DocumentProcessed

define "retval" text .

for DocumentReadBack with Processed = Not Processed ;

enter a record in DocumentProcessed

Dummy := MemoStringBetween(Body,DocumentReadBack Body,"DocID:","/DocID"); -- Read aut the string between DocID: and /DocID (case sensitive!!) Dummy is necessary to have a field to allocate to inside the Enter a Record (scope, could simply have used DocID but it would confuse you... any field would do)

DocID := Body ; -- copy the content of Body (memo) to DocID (only 255 will be copied, but that is all we need, MemoStringBetween is a memo function and will need a Destination Memo. We will change it to return 255 directly.)

Dummy := MemoStringBetween(Body,DocumentReadBack Body,"Date:","/Date") ; -- Same for date etc.

Date := Body ;

Dummy := MemoStringBetween(Body,DocumentReadBack Body,"Heading:","/Heading") ;

Heading := Body ;

Dummy := MemoStringBetween(Body,DocumentReadBack Body,"CustomerName:","/CustomerName") ;

CustomerName := Body ;

Dummy := MemoStringFrom(Body,DocumentReadBack Body,"Body:") . -- here we simply copy the remainder of the memo to Body.

modify records

Processed := Processed .


retval := DocumentOpen("DocumentProcessed") .


Written by DataEase 20/03/15 at 10:47:00 Dataease [{8}]FIVE