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!

How to: Store a variable in a memo field

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
0
0
GB
Hi all

I'm hoping this is the right forum for this question. We currently use part of the following to send some text and variables as an automated process which works fine:
Code:
oitem.htmlbody="<HTML> ;
  <H2>Order information</H2> ;
  <BODY>Regarding your order Ref: <B>[ "+ ;
  TRIM(transact)+" ]</B> which was received by us on <B>
  "+cdow(daterecevd)+" "+dmy(daterecevd)+" ]</B> ;
  <br><br>Thank you etc ;
  </BODY> ;
  </HTML>"
oitem.send
I posted a thread (thread1251-1068328) recently regarding Mike Gagnon's FAQ1251-4969 which resolved an issue with his help and mspratt (another Mike).
Part of Mike's code is:
Code:
With iMsg
  .Configuration = iConf
  .To = someone AT domain DOT com
  .CC = 
  .BCC = 
  .From = ouraddress AT ourdomain DOT com
  .Subject = test message
  .HTMLBody = [b]MEMOFIELDNAME[/b]
  .Send
Endwith
Ok. So here's the problem (at last!)
The memo field in a table MEMOFIELDNAME contains the HTML code that's created in FrontPage which the user copies and pastes into the memo field.
What I need to do is be able to insert the required variables or field names e.g. TRIM(transact) within the memo field so when the process starts the variable is recognised.
At the moment its shown like this:
Code:
Transaction number: [ "+TRIM(mtransact)+" ]
Instead of:
Code:
Transaction number: [ 1234567890ansact ]
Sorry for the long winded approach guys, but its difficult to explain otherwise and at least you can get an idea of whats already been done!

I look forward to any replies

Lee....

Visual FoxPro Versions: 6 & 9
Operating System: Windows XP
 
Would textmerge work for you. For example, instead of:

Code:
Transaction number: [ "+TRIM(mtransact)+" ]

you'd use:

Code:
Transaction number: [ "+<<TRIM(mtransact)>>+" ]

And then, this line:

Code:
  .HTMLBody = MEMOFIELDNAME

would become

Code:
  .HTMLBody = TEXTMERGE(MEMOFIELDNAME)
 
Hi TamarGranor

Thank you for your quick response. Unfortunately that threw up an error:
Code:
File textmerge.prg does not exist

Lee....

Visual FoxPro Versions: 6 & 9
Operating System: Windows XP
 
vfp6 doesn't have a Textmerge() Function, so vfp6 looks for a PRG instead. VFP6 has TEXT ... ENDTEXT, which is about the same. But vfp9 has textmerge().

If the functions like TRIM or CDOW you have in the Frontpage templates are really VFP code, then you could also do something with Evaluate() or put some Lparameters line and one or two commands in front and use Execscript() to generate the HTML body with filled in placeholders.

Indeed if you start from scratch Textmerge will give you fastest results. with the appropriate templates. Try for yourself, what is easiest done with Frontpage.

Bye, Olaf.
 
Hi Olaf

Thank you for your response.
VFP6 has TEXT ... ENDTEXT, which is about the same
Looking at that command, I'm not sure how I would overcome the fact that you start with TEXT (code) ENDTEXT as one command line in the code above is:
Code:
.HTMLBody =
So will it work with TEXT .... ENDTEXT all on one line?

Regarding your other comments, I found this:
Code:
?EXECSCRIPT("oForm=CREATEOBJECT('Form')"+CHR(13)+"?oForm.AutoCenter")
I'm sorry, but I've not used this command before and not sure how it works.
If you could me a brief example may be I could work from that. (The above code is all there is in the help file)

Many thanks
Lee

Visual FoxPro Versions: 6 & 9
Operating System: Windows XP
 
Hi Lee,

Only a slight variation of what you have will work.
For example, try this test:

Code:
transact = "123456"
daterecevd = DATE()
test=["<HTML> ;
  <H2>Order information</H2> ;
  <BODY>Regarding your order Ref: <B>"+ ;
  TRIM(transact)+"</B> which was received by us on <B> ;
  "+cdow(daterecevd)+" "+dmy(daterecevd)+" </B> ;
  <br><br>Thank you etc ;
  </BODY> ;
  </HTML>"]

? EVAL(test)

This produced the desired results. The main difference was removing a few brackets from within the string, and making the whole thing an expression... then using EVAL.

Let us know if this works...

Greg
 
Hi Lee, Hi Greg!

What I said:
Myself said:
If the functions like TRIM or CDOW you have in the Frontpage templates are really VFP code, then you could also do something with Evaluate()

But to present another solution with VFP6 style TEXTMERGE:
EXECSCRIPT() and TEXT..ENDTEXT might work for you in combination. First a little example of TEXT..ENDTEXT alone:
Code:
create cursor curNames (cName c(4))
insert into curNames values("Lee")
insert into curNames values("Greg")
insert into curNames values("Olaf")
local lcMerged
scan
TEXT TO lcMerged TEXTMERGE NOSHOW
Hi <<alltrim(curNames.cName)>>!

It's <<Datetime()>>, so I will now leave you.

Bye!
ENDTEXT
? lcMerged
?
endscan

So you can merge a template with records. The disadvantage of this example is, that the template is hard coded. But you can take it one step further and make it more generic, reading templates from a memo field of one table and the record(s) to be merged from (an)other table(s).

So you need a Template table with an appropriate template in it's memo field. Let's assume it's tabTemplates.mTemplate and the value of it is:
Code:
<html>
<body>
Regarding your order ref:<B><<tabTransactions.cTransaction>></B>
which was received by us on <B><<tabTransactions.dDatereceived>></B>
...
</body>
</html>
Also you have a table tabTransactions with data about the transactions.

Now you can merge that template with a record of tabTransactions with:

Code:
LOCAL lcTricky, lcScript, lcHTML
lcTricky = "TEXT"
TEXT TO lcScript TEXTMERGE NOSHOW
LOCAL lcText
<<lcTricky>> TO lcText TEXTMERGE NOSHOW
<<tabTemplates.mTemplate>>
END<<lcTricky>>
RETURN lcText
ENDTEXT
lcHTML = Execscript(lcScript)
? lcHTML

Notice I used TEXT..ENDTEXT to build a script in lcScript and used the Textmerge funcionality for that, too. That script includes a TEXT..ENDTEXT statement to evaluate the template. To have an innner TEXT..ENDTEXT within the outer TEXT..ENDTEXT I used the var lcTricky. After the outer textmerge lcScript will be:

Code:
LOCAL lcText
TEXT TO lcText TEXTMERGE NOSHOW
<html>
<body>
Regarding your order ref:<B><<tabTransactions.cTransaction>></B>
which was received by us on <B><<tabTransactions.dDatereceived>></B>
...
</body>
</html>
ENDTEXT
RETURN lcText

And when that is executed with Execscript() <<tabTransactions.cTransaction>> will be substituted by the value of tcTransaction and <<tabTransactions.dDatereceived>> by the value of tdDatereceived and the result will be returned to lcHTML.

TEXT ... ENDTEXT knows how to convert all var types to text, no expression is needed to convert it. Nevertheless you may have expressions within <<>>, like <<Date()>> or <<table.field>>. This makes it very flexible.

All this is much easier with the TEXTMERGE() function, as that would enable you to do the same with one line, if you also have tabTemplates and tabTransactions:
Code:
lcHTML = Textmerge(tabTemplates.mTemplate,.T.)
The .T. stands for recursive, which means if the result of the Textmerge has again merge expressions in it, these will also be evaluated. Although this isn't needed here, that would give you even more opportunities in storing merge expressions within tabTransaction fields. Much more powerful than TEXT..ENDTEXT.

Bye, Olaf.
 
gguidarelli
Many thanks for your post. I copied this into a PRG ran it but for some reason all it shows is this:
Code:
<HTML><H2>Order information</H2><BODY>Regarding your order Ref: <B>"+TRIM(transact)+"</B> which was received by us on <B>"+cdow(daterecevd)+" "+dmy(daterecevd)+" </B><br><br>Thank you etc</BODY></HTML>
Unless I've missed something?

OlafDoschke
Thank you for your response. I'll run your suggestion this evening and post back with a result as soon as I can.

Thanks again both
Lee....

Visual FoxPro Versions: 6 & 9
Operating System: Windows XP
 
Hi Olaf

Well I've tried your suggestions and received a few errors. One in particular was:
Code:
Alias 'TABTEMPLATES' is not found
If I have two tables, one called MYTABLE which has a memo field called HTMLCODE (which strangely enough contains the HTML code!) and another table called CUSTOMER with character fields TRANSACT (character 40) and DATERECEVD (Date), can you tell me what I need to substiute in your code and where?

Thank you in anticipation
Lee....

Visual FoxPro Versions: 6 & 9
Operating System: Windows XP
 
Hi Lee,

The only thing you need to substitute is the merge expression <<tabTemplate.mTemplate>>, which in your case would be <<myTable.HTMLCode>>.

Then in the HTMLCode memo you most probably have to change your template to contain the plain HTML code and <<customer.transact>> wherever you need that field displayed and <<customer.daterecevd>> whereever that field needs to be displayed.

So my code would just be modified to:
Code:
LOCAL lcTricky, lcScript, lcHTML
lcTricky = "TEXT"
TEXT TO lcScript TEXTMERGE NOSHOW
LOCAL lcText
<<lcTricky>> TO lcText TEXTMERGE NOSHOW
<<myTable.HTMLCode>>
END<<lcTricky>>
RETURN lcText
ENDTEXT
* set step on
lcHTML = Execscript(lcScript)
? lcHTML

The only preconditions are:
1. A HTML Template that's compliant to the TEXT...ENDTEXT function, as I said.
2. The tables myTable and Customer must be open of course.

If errors occur, uncomment the SET STEP ON line, then step into the Execscript call (with F8 key) and see how your template was integrated in the little Script. and what happens with it.

If the result displayed by ? lcHTML is right, you can store that to your mailbody with ...HTMLBody = lcHTML.

Bye, Olaf.

 
By the way gguidarelli's solution worked for me.

Here's a modification of your template, that would work with my script. This should be the content of your Table in the HTMLCode memo:
Code:
<HTML>
<H2>Order information</H2>
<BODY>
Regarding your order Ref: <B><<customer.transact>></B>
which was received by us on <B><<customer.daterecevd>></B>
<br><br>
Thank you etc
</BODY>
</HTML>

Bye, Olaf.
 
In my tests I learned TEXT..ENDTEXT works recursive. So my script to produce lcHTML can be reduced to simply:
Code:
LOCAL lcHTML
TEXT TO lcHTML TEXTMERGE NOSHOW
<<myTable.HTMLCode>>
ENDTEXT

In a first step the content of myTable.HTMLCode replaces <<myTable.HTMLCode>>, but then the textmerge expressions within that are also 'executed', so you end up with the transact number and date inserted into lcHTML right away.

Simple enough?

Bye, Olaf.
 
Hi Olaf

Sorry for not posting back but things have been realy busy. Not had a chance to try out your last suggestions, but will do soon.

Lee [thumbsup2]

Visual FoxPro Versions: 6 & 9
Operating System: Windows XP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top