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!

Creating string from list of results

Status
Not open for further replies.

mjohns10

MIS
Feb 27, 2007
12
0
0
US
Hello,
I'm attempting to create a string of text from a list of results

Answer
------------
value1
value2
value3
value4
value5


My goal is to loop through that list and finally display a string that I could insert into a more legible version of text, as in a typical paragraph, for instance:

"value1, value2, value3, value4, value5" (so, this post-process string would be a formula: {@result})

which I could then use in another formula...

{@longtext} = "The person owns these items: "+{@result}+" and would like to see what they are worth..."

Displaying:

The person owns these items: value1, value2, value3, value4, value5 and would like to see what they are worth...

Possibly, if I can get a handle on this operation, I'll maybe add an "and" in front of whatever the last value is (it won't always be the same number of results)

Lastly the above "Answer" field data will be generated in a subreport. I'm not sure if this operation should be performed in the subreport, or if I'll pass a shared variable(s)

Hopefully some kind genius can point me in the right direction. Let me know if I can provide any other details that might help! Thanks!!
 
is value 1 through 5 in your example 5 different records? is there any grouping involved in the report?

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

 
yes, each value is one record

there is a grouping on the "user" and each user will have 1 or more 'value' records

the base report will link to the subreport from which the above records will be generated on the user field so each time this operation runs it will always be for only one user 
 
Add these formulas to the subreport:

//{@reset} for the group header:
whileprintingrecords;
shared stringvar x;
if not inrepeatedgroupheader then
x := "";

//{@accum} for the detail section:
whileprintingrecords;
shared stringvar x := x + {table.value} + ", ";

//{@display} for the group footer:
whileprintingrecords;
shared stringvar x;
if len(x)>2 then
left(x,len(x)-2)

In the main report, create a formula to pick up the shared variable:

whileprintingrecords;
shared stringvar x;
"The person owns these items: " + x + "and would like to see what they are worth..."

The sub MUST be in a section above the one containing this last formula, so the sub would be in GH_a if the text is in GH_b. To make the sub disappear, suppress all sections within the sub, format the sub to "suppress blank subreport" (in the subreport tab of the main report), and then format GH_a to "suppress blank section".

You also should have a reset formula in the main report, placed in the group footer:

whileprintingrecords;
shared stringvar x := "";

-LB
 
Wow, thanks a lot. I'm going to work on that in a bit.
 
This is working fantastically, thank you so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top