【发布时间】:2014-12-19 01:44:21
【问题描述】:
我有一个报告,我正在尝试修改以删除记录选择,因此报告将显示日期范围内的所有事件,但在数组中应用相同的过滤器,因此它只计算具有过滤器的事件我正在删除记录选择。
所以,在记录选择中,我有以下内容:
and {OBI_EquipmentMaster.EquipmentType}=3
这将报告仅限于分配了促销活动的驱动器(事件)。促销是设备类型 = 3。
但我想删除它并将这个过滤器放在数组公式中,以便在交叉表中只计算促销。
在我的数组构建器中,使用了以下公式:
whileprintingrecords;
stringvar d:= {OBI_EquipmentMaster.Description};
numbervar p:= {DriveProjectionAndCollectedTotals.ProcedureProjection};
numbervar pe:= {DriveProjectionAndCollectedTotals.ProceduresPerformed};
//numbervar et:= {OBI_EquipmentMaster.EquipmentType};
stringvar array ad;
numbervar array ap;
numbervar array ape;
numbervar c2:= 1;
numbervar n:=0;
// check to see if the description has been added to the string array
// if not, add it plus add the initial projection value to the number arrays
if not (d in ad) then
// tried to add filter for only certain equipment type - assigned to variable above
//if not (d in ad) and et=3 then
(
numbervar c:= c + 1;
redim preserve ad[c]; ad[c]:= d;
redim preserve ap[c]; ap[c]:= p;
redim preserve ape[c]; ape[c]:= pe;
)
else
// if the description is already in the array, find its position
// then add the new projection as a running total to the appropriate number array values
(
while c2 <= count(ad) do
(
if d = ad[c2] then (n := c2; exit while);
c2 := c2 + 1
);
ap[n]:= ap[n] + p;
ape[n]:= ape[n] + pe;
);
// grand running totals
numbervar gp:= gp + p;
numbervar gpe:= gpe + pe;
我对数组的修改包括为设备类型添加另一个变量:
numbervar et:= {OBI_EquipmentMaster.EquipmentType};
并在 If 语句中添加一行:
if not (d in ad) and *et=3* then
公式检查正常,但当我尝试运行报告时,我收到一条错误消息:
下标必须介于 1 和数组大小之间。
ap[n]:= *ap[n]* + p;
具体来说,它似乎不喜欢的ap[n]。
关于如何解决这个问题的任何建议?
【问题讨论】:
-
我猜问题出在
numbervar c,它在使用之前没有初始化...所以首先初始化为numbervar c:=0,然后将其用作c:=c+1 -
在我看来,您的解决方案过于复杂。为什么不插入一个保留记录选择的
{OBI_EquipmentMaster.EquipmentType}=3部分的子报表并在那里构建交叉表? -
嘿@Ryan,我实际上已经返回并创建了一个子报告,但现在我在报告中显示数据时遇到了一些问题,而 SQL 在 SSMS 中返回数据。我会再发一篇文章来解决这个问题。
标签: arrays crystal-reports subscript