如何将2个变量相加并将其存储到一个变量中 [英] How to sum 2 variables and store it into one variable

查看:221
本文介绍了如何将2个变量相加并将其存储到一个变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含2个不同子报告的mainreport。

I have a mainreport containing 2 different subreports.

我有一个来自subreport1的变量sum,例如10(类型为Integer)

I have a variable sum from a subreport1 for example 10(type Integer)

我有另一个变量sum来自另一个子报告2,例如2(类型整数)

I have another variable sum from another subreport2 for example 2(type Integer)

我已经成功地从每个子报告中检索了2个变量
现在我想在我的mainreport中创建一个总结2个变量的变量

I have successfully retreived the 2 variables from each of the subreports now I want to create a variable in my mainreport that sums up the 2 variables

所以现在在我的mainreport中我有3个变量

so now in my mainreport I have 3 variables

第一个变量名为VAR1,它来自子报告1

the first variable is called VAR1 and it came from subreport 1

Name                       VAR1
Variable Class             java.lang.Integer
Reset type                 Report
initial Value Expression   0

第二个变量是称为VAR2,它来自子报告2

the second variable is called VAR2 and it came from subreport 2

Name                       VAR2
Variable Class             java.lang.Integer
Reset type                 Report
initial Value Expression   0

最后一个变量叫做SUM

the last variable is called SUM

Name                       SUM
Variable Class             java.lang.Integer
Reset type                 Report
variable expression        new Integer($V{VAR1}.intValue() + $V{VAR2}.intValue() )
initial Value Expression   0

当我预览pdf时,SUM变量为NULL,VAR1和VAR2是整数值但是SUM变量总是NULL

The SUM variable is NULL when i preview the pdf , VAR1 and VAR2 are Integer values but the SUM variable is always NULL

是否可以在VAR1和VAR2之前评估SUM?

could it be that the SUM was evaluated before VAR1 and VAR2?

什么是我的问题?

推荐答案

您的怀疑是正确的,使用从子报表返回的值来计算其他变量的变量不起作用,因为常规变量值在子报表渲染和返回值之前计算。

Your suspicion is correct, using variables with values returned from subreports to calculate other variables does not work because "regular" variable values are computed before the subreports render and return values.

如果您只需要对返回的值求和,那么您可以做的一件事就是从两个子报表中返回值在同一个变量中,使用calculate =Sum作为返回值。这是从第一个子报告返回到VAR1的val1和相同的val1到SUM,其中calculate =Sum,并将val2从第二个子报告返回到VAR1,并返回到SUM,其中calculate =Sum。

If you only need to sum the returned values, one thing that you can do is to return the value from the two subreports into the same variable, using calculation="Sum" for the return value. That is return val1 from the first subreport to VAR1 and the same val1 to SUM with calculation="Sum", and return val2 from the second subreport to VAR1 and to SUM with calculation="Sum".

请注意,calculate =Sum是返回值而不是变量;用于返回值的变量通常需要计算=系统。

Note that calculation="Sum" is for the return value and not the variable; variables that are used for return values would typically need to have calculation="System".

这篇关于如何将2个变量相加并将其存储到一个变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆