How can I increment a variable with value of another variable in JasperReports? - ireport

This is existing question, but I'd like to know if I can do simple math calculation with variables in iReport, i.e.:
I have 12 variables named
MONTH1_end_total
MONTH2_end_total
MONTH3_end_total
...
MONTH12_end_total
All variables are of type java.math.BigDecimal.
My question is: can I create a GRAND_total variable in which I will use simple math add calculation like:
GRAND_total = MONTH1_end_total + MONTH2_end_total + MONTH3_end_total

Yes you can..
just use the simple math function like,
GrandTotal=MONTH1_end_total.add(MONTH2_end_total.add(MONTH3_end_total ))..
and so on
Regards,
Gopinagh.R

Related

0 to Variable in Pascal

Lets take this code for example;
If (Random) <> (0 to Variable) then
Its very simple, I just want it to do something if Random is different than 0 to another number set in that variable, im not sure how to do this tho
if you want to check if the variable is not in range from 0 to Variable, it's better to use the code:
if (Random1 < 0) or (Random1 > Variable) then ...
I'm not sure that the code
if not (Random1 in [0..Variable]) then ...
will work for Variable values out of range [0..255]
Sorry, I should of explained better, they are both integer, and Random cant be used since its an instruction, it has to be Random1.
But the answer is
"if not (Random1 in [0..Variable]) then. [0..Variable]"
Thank you very much #lurker.

Random number in Lua script Load Impact

I'm trying to create a random number generator in Lua. I found out that I can just use math.random(1,100) to randomize a number between 1 and 100 and that should be sufficient.
But I don't really understand how to use the randomize number as variables in the script.
Tried this but of course it didn't work.
$randomCorr = math.random(1,100);
http.request_batch({
{"POST", "https://store.thestore.com/priceAndOrder/selectProduct", headers={["Content-Type"]="application/json;charset=UTF-8"}, data="{\"ChoosenPhoneModelId\":4,\"PricePlanId\":\"phone\",\"CorrelationId\":\"$randomCorr\",\"DeliveryTime\":\"1 vecka\",\"$$hashKey\":\"006\"},\"ChoosenAmortization\":{\"AmortizationLength\":0,\"ChoosenDataPackage\":{\"Description\":\"6 GB\",\"PricePerMountInKr\":245,\"DataAmountInGb\":6,\"$$hashKey\":\"00W\"},\"ChoosenPriceplan\":{\"IsPostpaid\":true,\"Title\":\"Fastpris\",\"Description\":\"Fasta kostnader till fast pris\",\"MonthlyAmount\":0,\"AvailiableDataPackages\":null,\"SubscriptionBinding\":0,\"$$hashKey\":\"00K\"}}", auto_decompress=true},
{"GET", "https://store.thestore.com/api/checkout/getproduct?correlationId=$randomCorr", auto_decompress=true},
})
In Lua, you can not start a variable name with $. This is where your main issue is at. Once the $ is removed from your code, we can easily see how to refer to variables in Lua.
randomCorr = math.random(100)
print("The random number:", randomCorr)
randomCorr = math.random(100)
print("New Random Number:", randomCorr)
Also, concatenation does not work the way you are implying it into your Http array. You have to concatenate the value in using .. in Lua
Take a look at the following example:
ran = math.random(100)
data = "{\""..ran.."\"}"
print(data)
--{"14"}
The same logic can be implied into your code:
data="{\"ChoosenPhoneModelId\":4,\"PricePlanId\":\"phone\",\"CorrelationId\":\""..randomCorr.."\",\"DeliveryTime\":\"1 vecka\",\"$$hashKey\":\"006\"},\"ChoosenAmortization\":{\"AmortizationLength\":0,\"ChoosenDataPackage\":{\"Description\":\"6 GB\",\"PricePerMountInKr\":245,\"DataAmountInGb\":6,\"$$hashKey\":\"00W\"},\"ChoosenPriceplan\":{\"IsPostpaid\":true,\"Title\":\"Fastpris\",\"Description\":\"Fasta kostnader till fast pris\",\"MonthlyAmount\":0,\"AvailiableDataPackages\":null,\"SubscriptionBinding\":0,\"$$hashKey\":\"00K\"}}"
Or you can format the value in using one of the methods provided by the string library
Take a look at the following example:
ran = math.random(100)
data = "{%q}"
print(string.format(data,ran))
--{"59"}
The %q specifier will take whatever you put as input, and safely surround it with quotations
The same logic can be applied to your Http Data.
Here is a corrected version of the code snippet:
local randomCorr = math.random(1,100)
http.request_batch({
{"POST", "https://store.thestore.com/priceAndOrder/selectProduct", headers={["Content-Type"]="application/json;charset=UTF-8"}, data="{\"ChoosenPhoneModelId\":4,\"PricePlanId\":\"phone\",\"CorrelationId\":\"" .. randomCorr .. "\",\"DeliveryTime\":\"1 vecka\",\"$$hashKey\":\"006\"},\"ChoosenAmortization\":{\"AmortizationLength\":0,\"ChoosenDataPackage\":{\"Description\":\"6 GB\",\"PricePerMountInKr\":245,\"DataAmountInGb\":6,\"$$hashKey\":\"00W\"},\"ChoosenPriceplan\":{\"IsPostpaid\":true,\"Title\":\"Fastpris\",\"Description\":\"Fasta kostnader till fast pris\",\"MonthlyAmount\":0,\"AvailiableDataPackages\":null,\"SubscriptionBinding\":0,\"$$hashKey\":\"00K\"}}", auto_decompress=true},
{"GET", "https://store.thestore.com/api/checkout/getproduct?correlationId=" .. randomCorr, auto_decompress=true},
})
There is something called $$hashKey also, in the quoted string. Not sure if that is supposed to be referencing a variable or not. If it is, it also needs to be concatenated into the resulting string, using the .. operator (just like with the randomCorr variable).

Compound Expressions in a Function in Mathematica

I wanted to calculate the power sum S_p(x) = 1^p + 2^p + 3^p + ... + x^p using the code
powersum[x_,p_]:=sum=0;For[i=1,i<x,i++,sum=sum+i^p];sum
but it seems to output 0 every time. Why does it do that?
As written, Mathematica is parsing your expression like this:
powersum[x_,p_]:=sum=0; (*Definition ended here*)
For[i=1,i<x,i++,sum=sum+i^p];
sum
You need to use to wrap your expression in parenthesis to make them all part of the function definition.
powersum[x_,p_]:=(sum=0;For[i=1,i<x,i++,sum=sum+i^p];sum)
Often it is preferable to use Module[]:
powersum[x_,p_]:=Module[{sum},sum=0;For[i=1,i<x,i++,sum=sum+i^p];sum]
or
powersum[x_,p_]:=Module[{sum=0},For[i=1,i<x,i++,sum=sum+i^p];sum]
this is essentially the same as wrapping in () except sum is protected in a local context.
of course for this example you could as well use :
powersum[x_,p_]:=Sum[i^p,{i,1,x-1}]
or
powersum[x_, p_] := Range[x - 1]^p // Total

Random number in Uppaal

How can I create a random number when I define a global declaration in an Uppaal program?
I want to have a variable that contains a random number as in a C program:
int x = rand (100);
According to folks at Uppaal mailing list , this code snippet select: i : int[0,3]
will non-deterministically bind i to an integer in the range 0 to 3.
So, in Your case just use select: x : int[0, 100].
I think the proper answer is: it is not possible when defining the global declaration.
The syntax that #Kamiccolo provided I think is misleading: there does not exist a syntactic construct like "select: ..." in Uppaal.
The only possible way, at now, is:
add a global variable "int x = 0;"
add an initial transition whose "select" clause assign "x : int[0,100]", as the mailing list (and the manual) suggest

Setting a variable in a for loop (with temporary variable) Lua

I have a for loop in lua, and I'm trying to set variables inside that for loop using the iterator variable. I need it to set these variables:
damage1
damage2
damage3
damage4
damage5
damage6
damage7
damage8
damage9
damage10
damage11
Of course I'm not going to assign them all, as that would be breaking the rules of D.R.Y. (Don't Repeat Yourself). This is what I figured would work:
for i = 0, 11 do
damage..i = love.graphics.newImage('/sprites/damage/damage'..i..'.png')
end
Don't mind the love.graphics.newImage(), that's just a function in the framework I'm using. Anyways, can someone help?
Thanks in advance.
If you want to set global variables, set _G["damage"..i].
If you want to set local variables, you're out of luck.
Consider setting damage[i] instead.
If your variables are local variables, its impossible to do what you want since Lua erases the names during compilation. If your variables are properties of a table (like global variables are) then you can use the fact that table access is syntax sugar for accessing a string property in a table:
--using a global variable
damage1 = 17
--is syntax sugar for acessing the global table
_G.damage1 = 17
--and this is syntax sugar for acessing the "variable1" string property
--of the global table
_G["damage1"] = 17
--and you can build this string dynamically if you want:
_G["damage"..1] = 17
However, as lhf said, it would probably be much more simpler if you stored the variables in an array instead of as separate variables:
damages = {10, 20, 30, 40}
for i=1,4 do
damages[i] = damages[i] + 1
end
Wouldn't this be the best thing to do?
damages = {}
for i = 0,11 do
table.insert(damages, love.graphics.newImage("/sprites/damage/damage"..i..".png"));
end
And then call by damages[0], damages[1]. etc.

Resources