Forum > LazReport

[SOLVED]Using SUM function with variables

<< < (2/3) > >>

dseligo:
When you assign values you want to use in 'SUM', then do something like this in OnGetValue:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var myNum: Double;begin  ...  myNum := WhateverYouUseToGetValueFromStringList;  ParValue := myNum;
That way you will be sure that you are providing number and not string.

Guylain:
I tried with Val function, wich gives me a error code on the decimal separator. I change the cell content with a '.' instead of ','. This time Val is Ok, but still nothing with SUM.

I changed my program default decimal separator to '.'
Now the cells show numbers with '.' automatically. Even then the report shows row values with  the ',' decimal separator. And of course, the SUM gives '0'

I'll try to find if LazReport has his own decimal separator...
Edit: The code in LazReport handles both separator, using tryStrToFloat with '.' first and and ',' if unsuccessful. So the problem is somewhere else.
Edit:
I changed my computer regional parameters to use '.' instead of ',' as decimal separator: reports shows once again rows values with ',' and SUM=0.
I changed the format of both row values and total in LazaReport Memos to use ',': now I see '.' in rows values, but Sum=0

korba812:
You should convert string to a number in the OnGetValue handler. Don't let LazReport do this. I am sending a sample project.

Guylain:
I already tried something like yours with no success. Val function gives a double value as you suggested in preceding post.
Begin
   Cells[22,FRow] := StringReplace(Cells[22 ,FRow], ',', '.', []);
   Val(Cells[22 ,FRow], DblValue, Code);
   If Code = 0 Then ParValue := DblValue
                     Else ParValue := 0;
 end;

and your more robust solution, and each time with same result.
By the way, I can't run your sample project. Lazarus tells me there is no source code. And no form appears in the IDE. I use Lazarus 2.0.0

korba812:
I'm using version 2.2. Create a new project and replace unit1.pas and unit1.lfm files from my project. It should work.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version