Different behavior when printing a report!
Hi,
I got a report with some code behind
Public Shared Dim pTotalHorasSessoes As Integer = 0
Public Shared Dim pTotalHorasProcessadas As Integer = 0
Public Shared Dim onInitialize As Boolean = True
Function TotalHorasSessoes(ByVal IDSessao As Integer, ByVal IDSessaoAnterior As Integer, ByVal Duracao As Integer, ByVal Processado As String) As String
If onInitialize = True
onInitialize = False
pTotalHorasSessoes = 0
pTotalHorasProcessadas = 0
End If
If IDSessao <> IDSessaoAnterior
pTotalHorasSessoes += Duracao
If (IDSessao <> IDSessaoAnterior) AND (Processado = "P")
pTotalHorasProcessadas += Duracao
End If
return str(Duracao)
Else
return ""
End If
End Function
Protected Overrides Sub OnInit()
onInitialize = True
End sub
First of all the variables are Shared in order to keep the values when printing. A second problem appears. The values of var will duplicate at any refresh or print. For example 40, 80, 120...
So, i added a Override method to control whenever the report refreshes. Another problem appears, when i print the report for the first time everything is ok, print second time and the values will be duplicated, and if i continue print the values will stay
duplicated. For Example 40, 80, 80, 80....
What i miss here?
Thks,
Ricardo Silva, T: @devsilva B: http://blog.ricardosilva.pt
July 14th, 2011 2:04pm
Hi Ricardo,
Thanks for your question. If I understand your question correctly, the possible reason may be in this line
expression: If (IDSessao <> IDSessaoAnterior)
AND (Processado =
"P").
In your code, if Processado = "P",
pTotalHorasProcessadas be calculated twice.
Could you please tell me the default values of the four parameters in the function of TotalHorasSessoes
when you quoted it in your report?
Thanks,
Sharp Wang
Please remember to mark the replies as answers if they help you and unmark them if they provide no help.
Free Windows Admin Tool Kit Click here and download it now
July 18th, 2011 6:01am


