law Posted August 9, 2012 Share Posted August 9, 2012 Hi all, I wonder if its possible to do the following with the records comming from a sql query:say I have a report that has numerical values:count 1: 300 count 2: 289count 3: 256count 4: 220Is it possible to create a variable, an numeric Array that would contain the difference between the numbers? - like that:Integer[] arr = new Integer[ 300-289, 289-256, 256-220]I can imagine this is a variable with execution time "Now", but can it be an array? and if so, how would I set up such a variable?Big thanks in advance! Link to comment Share on other sites More sharing options...
cmatthews Posted August 10, 2012 Share Posted August 10, 2012 This works as a variable class type java.lang.Integer[] or java.lang.String[].In the expression you can parse or build out arrays, add to them, use the object.split(",") to populate the array, etc.Hope this helps, Link to comment Share on other sites More sharing options...
law Posted August 10, 2012 Author Share Posted August 10, 2012 Hi cmatthews,In the dropdown for "Variable Class" I see options java.lang.Integer, java.lang.String, java.util.List. I have the newest iReport version installed. Where would I set java.lang.Integer to be java.lang.Integer[]?When I had a variable declared as java.util.List ls, then setting var Expression to ls.add($F{myNumField}), I'd get an error on attempt to "Preview" the report - ls.add function was not allowed. It seems like a simple thing, but... Link to comment Share on other sites More sharing options...
cmatthews Posted August 10, 2012 Share Posted August 10, 2012 You should be able to add the [] to the end after you select it as the data type.I'm not sure about the list data type... don't use it much. Link to comment Share on other sites More sharing options...
law Posted August 10, 2012 Author Share Posted August 10, 2012 Ok, thank you, I was able to set it to be an array. Now when I have it set in Variable Expression to this: $V{ls}.add( $F{myfield} )I get no errors, but ls is a null when tested in the page summery. I tested Calculation set to Nothing and System, but the array is empty. I even dragged it into the page Detail, still a null.Post Edited by liw at 08/10/2012 21:21 Link to comment Share on other sites More sharing options...
law Posted August 10, 2012 Author Share Posted August 10, 2012 I changed Variable Expression from $V{ls}.add( $F{myfield} )to $F{myfield} So now, the array gets populated, but only with one value out many in the column. Does anybody have an idea how I could populate my array with every value of a specific field? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now