• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2741
  • Last Modified:

Ughh! Print parameter field in report title using a formula

This one is a real zinger.  I'm using Crystal 8.5.  I have created a parameter field named PL which is setup as such:

string value type
allow multiple values
discrete and range values

Now, the user will typically enter values such as:

01   (discrete)
02   (discrete)
03   10  (range)

The report accepts these multiple discrete and range values and shows the results with no issues.  

I want to show all of the parameter values in a title.  I know how to create a formula and place it on the report.
But the question is how do I construct the formula given how I have setup this particular parameter field?

After much research, here is what I have tried so far and none of my attempts pass the formula editor check for various reasons:

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-- Crystal Syntax

StringVar strResult := '';
NumberVar n;

for n := 1 to ubound({?PL})
do
(
   strResult := strResult + {?PL}[n];
);              ^---------------  A string is required here.

strResult


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-- Crystal Syntax

StringVar strResult := '';
NumberVar n;

for n := 1 to ubound({?PL})
do
(
   strResult := strResult + ToText( {?PL}[n] );
);                                 ^-----------------  A number, currency amount, boolean, date, time, date-time, or string is required here.

strResult


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-- Crystal Syntax

Join( {?PL},"," )
     ^---------------  A string array is required here.


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-- Crystal Syntax

Join(ToText( {?PL} ),"," )
            ^-----------------  A number, currency amount, boolean, date, time, date-time, or string is required here.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-- Basic Syntax

dim i as number
dim s as string
for i = 1 to UBound({?PL})
  s = s & Chr(13) & chr(10) &  {?PL}(i)
                              ^-----------------  A number, currency amount, boolean, date, time, date-time, or string is required here.
next
formula = s



-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-- Crystal Syntax

//Declare a variable to hold the number of items in the Multiple value parameter
Global NumberVar Counter := Count({?PL});


//Declare a variable to use in the For Loop
Global NumberVar i :=1;


//Declare a string variable to hold the resulting string
Global StringVar Display;


//Loop through all of the items in the parameter.  
//Extract each and add to a string
For i := 1 to  Counter Do
    (
//Add the first parameter value to the Display variable
    If i = 1 then
        ({?PL}[i];
        Display := Display + {?PL}[i])
                   ^---------------  A string is required here.

//Add a comma to the Display variable before adding subsequent parameter values
    Else If i < Counter then
        ({?PL}[i];
        Display := Display + ", ";
        Display := Display + {?PL}[i])
//Add the word 'and' to the Display variable before the last value rather than a comma
    Else
        ({?PL}[i];
        Display := Display + " and ";
        Display := Display + {?PL}[i])
    );


//Display the variable that holds the result
Display
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


Thanks in advance,
Preece
0
Preece
Asked:
Preece
  • 2
  • 2
1 Solution
 
bdreed35Commented:
Give this a try:

StringVar strResult := '';
NumberVar n;

for n := 1 to ubound({?PL})
do
(
    strResult := strResult + ", " + minimum({?PL}[n]);
    if minimum({?test}[n]) <> Maximum({?PL}[n])
    then strResult := strResult + " thru " & maximum({?PL}[n]);
);

mid(strResult,3)

I formatted it a bit different to try and make the values appear like you might want to read them
0
 
PreeceAuthor Commented:
Awesome!  And thanks for the quick response.  Would you please modify your code so that the result may read something like:

1, 2, 3, 4, (5-10), (11-15), (16-20), 21, 22

Thanks,
Preece
0
 
bdreed35Commented:
StringVar strResult := '';
NumberVar n;

for n := 1 to ubound({?PL})
do
(
    if minimum({?PL}[n]) <> Maximum({?PL}[n])
    then strResult := strResult + ", (" + minimum({?PL}[n]) & "-" & maximum({?PL}[n]) + ")"
    else strResult := strResult + ", " + minimum({?PL}[n]);
);

mid(strResult,3)
0
 
PreeceAuthor Commented:
After 3 hours of pulling my hair out, I'm really happy to have this resolved.  Thanks for your excellent solution.

Preece
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now