Operators in Variable Expressions

Hi

Whan trying to use operators in a variable expression (like < > - + ) I get error messages when trying to compile the report.

The error message:
The operator > is undefined for the argument type(s) Integer, int

My expression:
((new Integer(new String($V{totalTime}.toString().substring($V{totalTime}.toString().indexOf("."), $V{totalTime}.toString().length()))) > 60) ? (new Double((new Integer(new String($V{totalTime}.toString().substring($V{totalTime}.toString().indexOf("."), $V{totalTime}.toString().length()))) - 60) & (new Integer(new String($V{totalTime}.toString().substring(0, $V{totalTime}.toString().indexOf(".")) + 1))))) : $V{totalTime})

Could anyone please help me with this?

Kind Regards
Neil
ice_raven's picture
192
Joined: Aug 1 2006 - 10:34pm
Last seen: 17 years 2 months ago

12 Answers:

There are several unuseful things in your expression, what do you want print starting from totalTime ?

Giulio
giulio's picture
74163
Joined: Jan 2 2007 - 4:15pm
Last seen: 4 days 19 hours ago
I have a field which shows minutes as a double. (eg 20.07 minutes)
Then I have a variable which sums all these numbers to get a total that displays for each group.
Simply adding these numbers don't work as you can get 20.95 minutes.
All the expression does is get the number after the '.' and if it's above 60, minus 60 from it and ad 1 to the minutes.
But it doesn't want to compile because I'm using '>' and '-'.
ice_raven's picture
192
Joined: Aug 1 2006 - 10:34pm
Last seen: 17 years 2 months ago
Does 20.07 mean:
a) 20 mins and 07 sec
b) 20.07 mins
c) 20h 07min

?

Giulio
giulio's picture
74163
Joined: Jan 2 2007 - 4:15pm
Last seen: 4 days 19 hours ago
It means 20 minutes and 7 seconds.
But if it gets sumed, you can get 20 minutes and a 95th of a minute and this is not wanted.

Kind Regards
Neil
ice_raven's picture
192
Joined: Aug 1 2006 - 10:34pm
Last seen: 17 years 2 months ago
Hi Neil,

I understand the problem, but I can't figure out how do you perform the sum. I know that if you sum:

20.10 + 20.87 you get 40.97 (and you'll trnsform it in 41.37)

but what if you have:

20.50 + 20.59? you get 41.09 (and this can not be corrected because 09 is < than 60, but the correct number should be: 41.49, not 41.09)

So I suggest you to implement a custom Infrementer.

Attached there is a sample.

[file name=TIMES.zip size=4862]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/TIM...
giulio's picture
74163
Joined: Jan 2 2007 - 4:15pm
Last seen: 4 days 19 hours ago
Hi Neil,

I understand the problem, but I can't figure out how do you perform the sum. I know that if you sum:

20.10 + 20.87 you get 40.97 (and you'll trnsform it in 41.37)

but what if you have:

20.50 + 20.59? you get 41.09 (and this can not be corrected because 09 is < than 60, but the correct number should be: 41.49, not 41.09)

So I suggest you to implement a custom Infrementer.

Attached there is a sample.

[file name=TIMES-4c6459cf48f15cb5ead57fb9acbc20da.zip size=4862]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/TIM...
giulio's picture
74163
Joined: Jan 2 2007 - 4:15pm
Last seen: 4 days 19 hours ago
giulio wrote:
Hi Neil,
20.10 + 20.87 you get 40.97 (and you'll trnsform it in 41.37)

but what if you have:

20.50 + 20.59? you get 41.09 (and this can not be corrected because 09 is < than 60, but the correct number should be: 41.49, not 41.09)


I have tested my code in a Java program and it works. If the amount is smaller than 60, then it does nothing.
(I am using a shorthand if).

I would just like to know how I can use operators (Like + - < > ...) in a variable expression in iReports.

Kind Regards
Neil
ice_raven's picture
192
Joined: Aug 1 2006 - 10:34pm
Last seen: 17 years 2 months ago
Atatched is my jrxml and beneath is the block of code I use and the code I use.

Kind Regards
Neil [file name=CaseReports.zip size=3975]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/Cas...
Post edited by: ice_raven, at: 2006/08/03 06:21
ice_raven's picture
192
Joined: Aug 1 2006 - 10:34pm
Last seen: 17 years 2 months ago
I had a look at your code and it works.
I have changed it (basicaly rewrote it) to fit our needs.

Thank you kindly!!!!!!!!!!! ;)

Kind Regards
Neil
ice_raven's picture
192
Joined: Aug 1 2006 - 10:34pm
Last seen: 17 years 2 months ago

Hi Guilio,

I have the same problem with Pavel. Can you please share also to me the jrxml file? I can't download the file maybe it has been removed. 

Thanks,

 

-jenue

jenue's picture
57
Joined: Aug 19 2008 - 2:02am
Last seen: 15 years 1 month ago

Can you please give me that expression/code, because I'm facing the same problem...

 

Regards  Lodewijk

Lnederpel's picture
Joined: Nov 18 2007 - 8:49pm
Last seen: 15 years 10 months ago

Can you please give me that expression/code, because I'm facing the same problem...

 

Regards  Lodewijk

Lnederpel's picture
Joined: Nov 18 2007 - 8:49pm
Last seen: 15 years 10 months ago
Feedback
randomness