循环通过多值参数数组 [英] Looping through a multiple value parameter array
问题描述
我有一个允许多个值的参数。它对我的数据库中的名称字段。我想要做的是允许用户输入一个名称,然后水晶找到任何名称,如他们输入的任何名称。例如,你可以输入4个姓氏和水晶将返回任何人在名称字段中有任何这些名称。我可以得到喜欢工作很好,但只有当数组中有一个字符串。这是我的选择公式:
numbervar counter:= 1;
numbervar positionCount:= count({?Customer Name}); //我不知道把
放在这里。计数? UBound?
if {?Customer Name} [1]<> 'ALL'
then
(
while(counter< = positionCount)
do
(
{NAMEFIELD} like'*'&客户名称} [counter]&'*';
counter:= counter + 1;
);
)
else
如果{?Customer Name} 1] ='ALL'
then
true
)
此公式返回所有名称,而不是参数中的名称。
创建多值参数({?Customer Name})属性:
- 默认值:ALL
- 所有多个值:TRUE
在参数的选择列表网格中添加一行;提供'ALL'和'ALL'(不带单引号)
使用此文本创建自定义函数(命名为'Delimit'):
// Delimit()
//将数组中的每个值都放在**中,返回一个数组
Function(Stringvar Array params)
拆分(*+ Join(params,*,*)+*,,)
修改报表的记录选择公式:
如果{?Customer Name} ;>ALLthen
{TABLE.CUSTOMER_NAME} LIKE Delimit({?Customer Name})
Else
True
或者,创建一个公式以显示带有此文本的参数值:
// {@ Customer Name}
加入(Delimit({?Customer Name}),;)
I have a parameter that allows multiple values. Its for a name field in my database. What I want to be able to do is allow the user to put in a name and then have crystal find any name like any of the names they entered. So for example you could put in 4 last names and crystal would return anyone who had any of those names in the name field. I can get the "like" to work just fine, but only when there is one string in the array. Here is my select formula:
numbervar counter := 1; numbervar positionCount:=count({?Customer Name}); //I'm not sure what to put here. Count? UBound? if {?Customer Name}[1] <> 'ALL' then ( while(counter <= positionCount) do ( {NAMEFIELD} like '*' & {?Customer Name}[counter] & '*'; counter := counter + 1; ); ) else if {?Customer Name}[1] = 'ALL' then true )
This formula returns all of the names, not the ones in the parameter. Any ideas on what I'm doing wrong?
解决方案Create a multi-value parameter ({?Customer Name}) with these properties:
- Default Value: ALL
- All multiple values: TRUE
Add a row to the parameter's pick-list grid; supply 'ALL' and 'ALL' (without single quotes)
Create a Custom Function (named 'Delimit') with this text:
// Delimit()
// enclose each value in array in **, returning an array
Function (Stringvar Array params)
Split("*" + Join(params, "*,*") + "*", ",")
Modify the report's record-selection formula:
If {?Customer Name}<>"ALL" Then
{TABLE.CUSTOMER_NAME} LIKE Delimit({?Customer Name})
Else
True
Optionally, create a formula to display the parameter's values with this text:
//{@Customer Name}
Join( Delimit({?Customer Name}), ";")
这篇关于循环通过多值参数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!