Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Array Help needed Post Reply Post New Topic
Author Message
avaj
Newbie
Newbie


Joined: 26 Sep 2007
Online Status: Offline
Posts: 30
Quote avaj Replybullet Topic: Array Help needed
    Posted: 29 Mar 2011 at 10:18am
I'm using Crystal 2008 and trying to print out the descriptions for a multiple parameter.  this is the formula I created but I keep getting the first description in the output no matter what the parameter field has.
 
FORMULA:
local stringvar array prtvalue;
local numbervar index := 1;
redim prtvalue [UBound ({?Merchants})];
for index := 1 to UBound ({?Merchants}) step 1 do
(
 if {?Merchants} = "0" then
    prtvalue[index] := "CVS"
else
 if {?Merchants} = "1" then
   prtvalue[index] := "All"
else
 if {?Merchants} = "2" then
   prtvalue[index] := "Giant"
else
 if {?Merchants} = "3" then
    prtvalue[index] := "WMATA"
else
 if {?Merchants} = "4" then
   prtvalue[index] := "PRTC"
else
 if {?Merchants} = "5" then
   prtvalue[index] := "Commuter"
else
 if {?Merchants} = "6" then
   prtvalue[index] := "Zodiac"
else
 if {?Merchants} = "7" then
   prtvalue[index] := "Independent"
);
Join (prtvalue, "; ");
 
Merchants = (0,2,3,4) and the output I get is CVS; CVS; CVS....
 
What am I doing wrong?  Every other way I have tried gives me an error.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 30 Mar 2011 at 3:43am

Merchants is an array, and as such you need to access its values using the array notation (at least that is what the code says).

If Merchants is really a comma delimited string, then you would need to first make it an array, using split, and then access the resulting array using array notation.
 
you probably want:
if {?Mercant}[index] = "0" then...
 
HTH
IP IP Logged
avaj
Newbie
Newbie


Joined: 26 Sep 2007
Online Status: Offline
Posts: 30
Quote avaj Replybullet Posted: 30 Mar 2011 at 4:35am
Thanks, that gave me exactly what I wanted.  I guess I thought Crystal was automatically handling the parameter field.
IP IP Logged
dbodell
Groupie
Groupie
Avatar

Joined: 08 Nov 2011
Location: United States
Online Status: Offline
Posts: 53
Quote dbodell Replybullet Posted: 29 Nov 2011 at 12:08pm
Can I continue this question a bit? It is exactly the problem I am trying to solve but I am confused about something:  In your code you seem to be specifying each possible value that the user could pick in your parameter and then coming up with the corresponding description. I have a parameter that is a long list of doctors. The value of the parameter is the doctor's ID and the description is the doctor's Name. I don't know at any time what values the user might select from the list. I can't imagine specifying each of the possible doctor ID values for my parameter in order to determine the doctor's name associated with it. How would I tell the report to get the doctor's name without having to list all of the possible values for the array? I am not a newbie to Crystal per se, but I am to variables and such, so please explain in newbie terms if you can.
 
Let's call my parameter {?Doctor}.  The value field is DOC_ID and the description field is DOC_NAME.
 
Thank you so much in advance.
Thanks,
D. Bodell
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 30 Nov 2011 at 8:46am
There is bound to be a way, but it eluding me right now.
 
Getting a list of IDs is easy, but I am missing how to get a list of names.
 
This is 'simplest' solution that comes to mind:
in the Report/Selection Formulas/Record add a shared variable or 2 like:
shared stringvar drID;
shared stringvar drName;
local stringvar did;
local stringvar dname;
local stringvar p := "|";
did := {table.drID};
dname := {drTable.drName};  //I am assuming that there is a table of doctors and they are linked to some other table via their ID
 
if instr(drID, p + did + p) = 0 then (
  if drID = "" then drID := p;
  if drName = "" then drName := p;
  drID := drID + did + p;
  drName := drName + dname + p;
);
 
//any othe logic you might want
 
this will give you 2 pipe delimited strings.
 
Then you can write a formula like above that will split the strings into arrays
shared stringvar drID;
shared stringvar drName;
local stringvar array drIDarray := split(drID, "|");
local stringvar array drNamearray := split(drName, "|");
 
then you can loop through the parameter list, match it to the ID array, and having that index, get the name from the drNamearray array using the index.
 
I would think that there is a more direct route, but this is all that comes to mind.
 
If you find a better way, that's fine.  My goal is to guide others to a solution.
 
HTH
 
 
IP IP Logged
dbodell
Groupie
Groupie
Avatar

Joined: 08 Nov 2011
Location: United States
Online Status: Offline
Posts: 53
Quote dbodell Replybullet Posted: 30 Nov 2011 at 10:07am
Thank you very much lockwelle. It took a lot of thought to come up with something like that. I really hope there is something easier than that to solve this. It seems kind of ridiculous that Crystal wouldn't allow you to refer to the description of the parameter value. Microsoft SSRS does this very simply by refering to the label of the parameter instead of the value of the parameter. Obviously this is one thing that SSRS does better than Crystal. There are plenty of things Crystal does better than SSRS. Wish I had something that combined all of their functions. Oh well.
Thanks,
D. Bodell
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.