Saturday, February 25, 2012

can anyone help me with a nested count?

Hi All,

I am trying to do a nested count and cannot seem to get it to work. I do realize I cannot do this within the expression so I have been trying to use the code block (report > report properties > code tab) to do this and I have zero experience with VB.

This is for a PO delivery report. The first expression is just counting how many lines on an individual PO are late divided by total number of lines on the PO. In second expression I would like to count how many POs that have a late line on it.


Here is what I have so far.

Expression 1 with count function (this work properly):
=iif(Fields!DS_Desired_Recv_Date.Value is nothing,
((Count(IIF(Fields!LAST_RECEIVED_DATE.Value > Fields!DESIRED_RECV_DATE.Value,1,Nothing))/Count(Fields!LINE_NO.Value))),
((Count(IIF(Fields!ACTUAL_RECV_DATE.Value > Fields!DS_Desired_Recv_Date.Value,1,Nothing))/Count(Fields!LINE_NO.Value))))

Code block:
Private Shared count as Integer
count=0
Public Function IncrementCount() As String
count = count +1
IncrementCount = CStr(count)
End Function

Expression 2
=iif(Fields!DS_Desired_Recv_Date.Value is nothing,
((Count(IIF(Fields!LAST_RECEIVED_DATE.Value > Fields!DESIRED_RECV_DATE.Value,1,Nothing))/Count(Fields!LINE_NO.Value))),
((Count(IIF(Fields!ACTUAL_RECV_DATE.Value > Fields!DS_Desired_Recv_Date.Value,1,Nothing))/Count(Fields!LINE_NO.Value))))

& IIf(iif(Fields!DS_Desired_Recv_Date.Value is nothing,
((Count(IIF(Fields!LAST_RECEIVED_DATE.Value > Fields!DESIRED_RECV_DATE.Value,1,Nothing))/Count(Fields!LINE_NO.Value))),
((Count(IIF(Fields!ACTUAL_RECV_DATE.Value > Fields!DS_Desired_Recv_Date.Value,1,Nothing))/Count(Fields!LINE_NO.Value)))) > 0, Code.IncrementCount(), Nothing)

The error:
[rsCompilerErrorInCode] There is an error on line 2 of custom code: [BC30188] Declaration expected.
Build complete -- 1 errors, 0 warnings.

Also "Code.IncrementCount()" is underlined with red zigzag indicating an error.

How do I get the code block to work with expression 2?

Thanks,

Blair

I would try changing this: Private Shared count as Integer

To this: Dim count as New Integer()

I've never used that code block portion, but it seems to me that you are trying to declare variables as part of a class when they aren't really in a class?

There is an error on line 2 of custom code: [BC30188] Declaration expected

This indicates to me that the variable count never truly got declared properly.

|||ok, thanks I will give that a try.

No comments:

Post a Comment