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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Letter Punctuation/Grammar 1

Status
Not open for further replies.

WestView

Technical User
Jan 7, 2003
67
US
Hello All,

I’ve been tasked to create a Form Letter that lists products a client has ordered. I have a formula that works well to pull the all the product fields (while suppressing the *NULL* values):
----------------------------------------------------------------------------------------------------
global stringvar Address1 := "";
global stringvar Address2 := "";
global stringvar Address3 := "";

if not IsNull({Product_Order_1}) and {Product_Order_1}
<> "" then Address1 := {Product_Order_1} + chr(44);
if not IsNull ({Product_Order_2}) and {Product_Order_2}
<> "" then Address2 := {Product_Order_2} + chr(44);
if not IsNull ({Product_Order_3}) and {Product_Order_3}
<> "" then Address3 := {Product_Order_3} + chr(44);

Address1 & Address2 & Address3
-----------------------------------------------------------------------------------------

This issue I’m having is that I must place the proper grammar/punctuation between the products. For example, if the client only ordered Product_1 then the sentence would read:

“Dear customer. Thank you for ordering Product_1.”

However, if the client ordered Product_1 & Product_2 then the sentence would read”

“Dear customer. Thank you for ordering Product_1 and Product_2.”

And, if the client ordered Product_1 & Product_2 & Product_3 then the sentence would read:

“Dear customer. Thank you for ordering Product_1, Product_2 and Product_3.”

I have no idea how to go about achieving this. My hunch is the solution is in an array. But how?

Please HELP! Any/all help would be greatly appreciated!!!!

Thanks,

Tom
 
I'd use a set of formula fields. For Product_1
Code:
if not isnull(Product_1)
then
if isnull(Product_2)
   if isnull(Product_3) then Product_1
   else Product_1 & " and " & Product_3

and so forth.



[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
If you amend your formula to include a space after each comma (because I think you need one) by replacing chr(44) with ", ", you could do the following. First also add a variable x to your formula and then amend your last line as follows:

stringvar x;

x := Address1 & Address2 & Address3

Then add to this formula or create a second display formula that you use in your letter:

whileprintingrecords;
stringvar x;

if instrrev(left(x,len(x)-2),", ") > 0 then
(
left(left(x,instrrev(left(x,len(x)-2),", ")-1) + " and"+
mid(x,instrrev(left(x,len(x)-2),", ")+2),
len(left(x,instrrev(left(x,len(x)-2),", ")-1) + " and"+
mid(x,instrrev(left(x,len(x)-2),", ")+2))-2)
) else
left(x,len(x)-2)

-LB
 
LB,

Thank you for your reply!

I used your second suggestion and created a second formula to display the records. However, your the formula seems to only grab Address_3 for all records.

Could you give me an example of how I would combine these formulas? I tried, but only got error messages.

Thanks again!!!

- tom
 

LB,

D'oh! Never mind. I see the error. I forgot to put the semicolan at the end of the variable declaration.
--------------------------------------------------------
x:= Address1 & Address2 & Address3;

if instrrev(left(x,len(x)-2),", ") > 0 then
(
left(left(x,instrrev(left(x,len(x)-2),", ")-1) + " and " +
mid(x,instrrev(left(x,len(x)-2),", ")+2),
len(left(x,instrrev(left(x,len(x)-2),", ")-1) + " and " +
mid(x,instrrev(left(x,len(x)-2),", ")+2))-2)
) else
left(x,len(x)-2)
---------------------------------------------------------

Your code worked BEAUTIFULLY! Can't thank you enough. I would never have come up with it.

Thanks again!!!

- Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top