views:

1738

answers:

4

I have a report which I'm working on which has an input parameter (strSchoolIds) that is a string of comma separated list of unique schoolIds. I'd like to convert this string into a number array which can then be used in the record selection formula. Here is what I've come up with so far. But whenever I view the report just the first schoolId gets used.

Example input string for strSchoolIds might be 1,3,63,237,281
The resulting SQL query I'd like would be similiar to this

Select name, phone, numStudents 
from schools
where schoolId in (1,3,63,237,281) and active =1

My current code is:

StringVar Array schools := Split ({?strSchoolIds}, ",");
Local NumberVar arrLen := UBound( schools );
Local NumberVar i := 1;

NumberVar Array schoolIdsArray;
While i <= arrLen Do
(
    schoolIdsArray[i] = ToNumber(Trim(schools[i]));
    i := i + 1;
);


{Schools.schoolId} in schoolIdsArray
and {Schools.active} = 1;
+2  A: 

I've got code similar to the:

{Schools.schoolId} in schoolIdsArray

and it works properly.

Are you sure your array is getting populated properly?

You can test this quickly by adding a new unbound string field and placing this in the formula

ToText(schoolIdsArray[1]) + ", " + ToText(schoolIdsArray[2])
Nathan Koop
I started with trying to create a formula field as suggested but received the error ``. So then I created a formula field on the schools string array and it displays correctly when I specify the index. I followed this idea through and displayed the values for ToText(UBound( schools )); ToText(arrLen);i before and after the while control structure ToText(i);All values came back correct.When Crystal Reports gets to the statement schoolIdsArray[i] = ToNumber(Trim(schools[i]));it chokes with the error `A subscript must be between 1 and the size of the array`
lmingle
oops - the first error received was `A subscript must be between 1 and the size of the array `
lmingle
+2  A: 

I figured it out after using Nathan Koop's suggestion and building upon it to debug with. Turns out I needed to Redim the schoolIdsArray with the arrLen of the string Array schools before adding values to it.

StringVar Array schools := Split ({?strSchoolIds}, ",");
Local NumberVar arrLen := UBound( schools );
Local NumberVar i := 1;
NumberVar Array schoolIdsArray;
Redim schoolIdsArray[arrLen];
While i <= arrLen Do
(
    schoolIdsArray[i] = ToNumber(Trim(schools[i]));
    i := i + 1;
);

{Schools.schoolId} in schoolIdsArray
and {Schools.active} = 1;
lmingle
A: 

I have the similar issue and it does not work for me. The parameter {?Domain} get data from .NET apps as the string with values 1,4,9,25

In the selection criteria I try to type {vwAgregateRepByAPO_0.DOMAIN} in [{?Domain}] and crystal report return error. So I try the script: StringVar Array StrArray := Split ({?Domain}, ","); Local NumberVar arrLen := UBound( StrArray ); Local NumberVar i := 1;

NumberVar Array DomainArray; Redim DomainArray[arrLen]; While i <= arrLen Do ( DomainArray[i] = ToNumber(Trim(StrArray[i])); i := i + 1; );

{vwAgregateRepByAPO_0.DOMAIN} in DomainArray;

.......... No errors but report generated as a blank page. Any one has idea?

Thank you. Paul

Paul Nersesov
A: 

in this part of the code, I added a colon and it worked...

schoolIdsArray[i] := ToNumber(Trim(schools[i])); 

Hope this helps...

Matt