Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Text File to Scattered Memo Variable

Status
Not open for further replies.

SSDESIGN

Programmer
May 11, 2003
71
0
0
US
After scattering a dbf containing a memo field, I would like to add a text file to the memo variable. The path and text file name are preloaded in a variable. I've been trying e_body = e_body + e_sign. e_sig is a four line signature text file.

After trying different combinations - &e_sign, EVAL(&e_sign), EVAL(e_sign) - the full path would be added to the memo variable or a syntax error would occur.

All suggestions would be appreciated....
 
Try the following:

APPEND MEMO <memo field> FROM <file> [OVERWRITE]

From the 1991 Edition of the "FoxPro Commands & Functions" book:

"When data is read from a file, the entire contents are added to the end of the memo field in the current record... If the OVERWRITE keyword is included, the current contents of the the memo field will be overwritten (replaced) with the contents of <file>."

C.Davis

 
Thanks for the APPEND MEMO suggestion. I tried it and it did not work. The command expects the field your are appending to is in a dbf not a variable.

Again, thanks...
 
You'll have to read the file in before you can append it. In more recent versions of FoxPro, you can use FileToStr() to do that, but in FoxPro 2.x, you'll need the low-level file functions.

Look up FOPEN() and FREAD() in Help.

Tamar
 
Depending on your goal -- you could "APPEND MEMO" prior to scattering -- the variable should then contain the file contents -- you should then be able to concatenate e.g.
(untested)
myVar = myPath + myFileName
Use myDBF
APPEND MEMO myMemo FROM test.txt
SCATTER MEMO TO myMemoVar
myVar = myVar + m.myMemoVar

m.myMmeoVar = myVar

GATHER FROM ...

-- CD.
 
CDavis - Thanks for the suggestion.

I believe it will work except that the user is given the option to quit out without saving back to the DBF. Also, since the dbf record has a sequence control number, we would like to only issue control numbers to active records.

What we are trying to do is to send an email.

The steps would be as follows:
SCATTER email.dbf fields; Load known data including adding a signature to the memo field; open the fields for editing with the option of quitting out; on save GATHER all fields into email.dbf.

It's the loading of the signature into the memo body of the email that is the problem.

Thanks for your support.
 
Another possible way to address this would be to have a stand alone dbf with the same structure as your email.dbf where you could temporarily load the data as opposed to using variables. Your temp dbf would only need to have one record and you could manipulate the data in that record and then decide whether to save (replace) the data in your main email.dbf

Post a code snippet if you want us to look more closely at what you are trying to do and we may be able to give you additional comments.

CDavis
 
One quick question...

Can you scatter from one dbf and gather into a different dbf?

Just wondering...

If it can be done, we're off and running..

Thanks for all of the support....
 
Yes -- GATHER copies data from a set of memory variables into the current record of the active database. If MEMVAR is included, data is transferred to the current record from memory variables with the same names as fields in the database. So a SCATTER from one table will create memory variables with names the same as the field names. If the second DBF has the same structure the GATHER will work on the second table.

You would need to SELECT the appropriate table prior to the GATHER. You would also need to ensure that the record pointer is on the appropriate record prior to the GATHER. e.g.

USE myDBF1 IN 0
Use myDBF2 IN 0
SELECT myDBF1
***move the record pointer to the appropriate record***
SCATTER MEMO MEMVAR
***manipulate variables as needed***
SELECT myDBF2
***move the record pointer as needed or APPEND BLANK****
GATHER MEMVAR MEMO

***alternatively you could use the REPLACE command to selectively store memory variable data in the various fields of the record. You could also use the REPLACE command to selectively copy data from the fields of one table to the other table without the use of intermediate variables.***

CDavis
 
All because a memo variable can not be loaded with a text file, the following work around seem to be the suggested procedure:

SELECT 0
USE email
COPY STRUCTURE TO temp_em
USE temp_em
* e_body is the variable for the body of the email
* emsig001 is the signature text file
APPEND MEMO e_body FROM emsig001
SCATTER MEMVAR MEMO
* close temp_em
USE
DELETE temp_em
SELECT email.dbf
* load variables with required values
* record memvar to email.dbf
GATHER MEMVAR
* continue processing...

Well done all... THANKS....
 
I think you have the basics down. You'll need to include the keyword MEMO in the GATHER command. An alternative would be to have a table loaded with the signature information instead of stand alone text files.

USE emsig.dbf IN 0
***navigate to the appropriate record in the signature table***
USE email.dbf IN 0
***navigate to the correct record or APPEND BLANK***
***process the fields as needed***
REPLACE email.e_body WITH emsig.mySigField ADDITIVE
***continue processing as needed***

Or as Tamar suggested above you could use low level file functions to read the signature text file directly into a memory variable and then concatenate the two variables or you could use REPLACE ADDITIVE to append the signature directly to the end of your e_body memo field.

Let us know how it works out.

CDavis
 
Well, I thought it was a done deal...

Oh well....

When I get to the COPY STRUCTURE statement while running a compiled PRG, I got errors:

"Source not available"
"File access denied"

SELECT 0
USE email
COPY STRUCTURE TO temp_em
USE temp_em

email is open
temp_em does not exist.


 
There could be a number of reasons for the messages you are receiving. Have you excluded or included the table files from the project. Is the email file in the current directory or included in your path?

If you want both tables open at the same time you could modify your code slightly--

USE email IN 0
COPY STRUCTURE TO temp_em
SELECT 0
USE temp_em IN 0


Some commands are only available in the development environment but I don't think that is the case with COPY STRUCTURE -- maybe someone else can comment with other ideas.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top