Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Comparing Strings to Parameters Post Reply Post New Topic
Author Message
ChiBlackhawks
Newbie
Newbie
Avatar

Joined: 05 May 2009
Location: United States
Online Status: Offline
Posts: 5
Quote ChiBlackhawks Replybullet Topic: Comparing Strings to Parameters
     Posted: 13 Feb 2012 at 7:56am
I have 3 string parameters that the user can choose one or more of.
For example, they are 'p0' 'n0' and 'c0'.
There is a character field in my database, called ChemString, that could possibly contain 0, 1, 2, or all 3 of those strings.  If they are in the ChemString and there is more than one of them, they would be separated by a comma and a space, like, ''p0, c0'.
So, what I need to do is find all of the records in the database where ChemString contains all of the parameter values that were chosen by the person who ran the report.
So, if just 'n0' was chosen then I would want all of the database records where 'n0' was in ChemString.
If the user selected both 'n0' and 'p0', I would want all of the database records that had both of those values in ChemString.
 
I tried this in the Record Selection Formula........
{Site.Version} = 0
  AND Site.ID = 100
  AND ({?ParamField}[1] IN {ChemString} OR
           {?ParamField}[2] IN {ChemString} OR
           {?ParamField}[3] IN {ChemString})
 
I get this error, "A subscript must be between 1 and the size of the array"
 
Any help on how to accomplish this would be greatly appreciated.
Thanks!
 
This is CR Ver. 10
IP IP Logged
kostya1122
Senior Member
Senior Member
Avatar

Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
Quote kostya1122 Replybullet Posted: 13 Feb 2012 at 8:36am
you could try
{Site.Version} = 0
  AND Site.ID = 100
  AND (if isnull({?ParamField}[2])and isnull({?ParamField}[3]) then  {ChemString} like "*{?ParamField}[1]*" else
   if    isnull({?ParamField}[3] ) then     {ChemString} like "*{?ParamField}[1]*"+ "*{?ParamField}[2]*" else
          {ChemString} like "*{?ParamField}[1]*" +"*{?ParamField}[2]*" +"*{?ParamField}[3]*" )

haven't tested it, so not sure if this will work


Edited by kostya1122 - 13 Feb 2012 at 8:41am
IP IP Logged
ChiBlackhawks
Newbie
Newbie
Avatar

Joined: 05 May 2009
Location: United States
Online Status: Offline
Posts: 5
Quote ChiBlackhawks Replybullet Posted: 13 Feb 2012 at 10:14am
Kostya,
Thank you so much for taking a look at this.  I understand what you are trying to do and I was optimistic that it was going to work, but when I syntax check the record selection formula, CR highlights the
{?ParamField}[2] in the first isnull function and it says, "A field is required here".
I noticed the "and" was right up against the right parenthesis and thought maybe that was the problem, but it wasn't.
 
UPDATE: I just read in another forum that IsNull() is only for database fields.  Don't know if that's correct or not, but if it is then that would explain the error.
 
ANOTHER UPDATE: I changed all of the IsNull() functions to
{?ParamField}[2] = ''
That got rid of the "A field is required here" syntax error, but when I run the report I'm back to the error message...........
"A subscript must be between 1 and the size of the array".
When I run the report I'm only selecting 1 of the 4 possible values.  I wonder if the problem is that CR only sees the ParamField array to be a length of one because that's all that was selected.  If so, I don't know how to check how many of these options the user has picked.
As I'm typing this I'm thinking maybe there's some kind of ArrayLength() function I could use.
I hate CR.  Especially this Ver. 10
I don't understand how we can be 3 versions behind the most current one.
 
YET ANOTHER UPDATE: I think I've got it.  The array size theory seems to be the way to go.  I changed the comparison to be.......
if UBound({?ParamField}) = 1
   then {ChemString} like "*{?ParamField}[1]*" 
   else
      if UBound({?ParamField}) = 2
      then {ChemString} like "*{?ParamField}[1]*" + "*{?ParamField}[2]*" 
           etc.  etc.
 
Thanks for your help!!!
 


Edited by ChiBlackhawks - 13 Feb 2012 at 11:00am
IP IP Logged
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