Set & Get functions
Hi All,
My report consists of 1 Master section and this master section is calling 3 sub reports. The master section is grouped by a column called "ProductCode".
In the first subreport, I'm trying to use the footer totals in the masterdata band for percentage calculations, eg, (<Col1>/<Total Col1>) * 100 and place this column adjacent to Col1.
In the footer band's OnBeforePrint, I type the code -
set(<Query1."BookingValue">,sum(<Query2."Bookings">)) ; (I'm assigning the sum(bookings) to Bookingvalue of the first query from where this sub report is being called)
Then I add a memo object in the masterdata band next to the bookings column. In the OnBeforePrint event of the new memo, I write the following code -
memo89.text:=formatfloat('#0.0',(<Query2."Bookings">/get(<Query1."BookingValue">))*100);
But When I run the preview, I get the following error :
"Could not convert variant of type(null) into type(OleStr)" OR sometimes
"Could not convert variant of type(null) into type(Double)" .
I used the same method for another report and it works, but I'm getting and error for this one. Can someone please let me know where I'm going wrong,it's very important.
Thanks & Regards,
Sriram
My report consists of 1 Master section and this master section is calling 3 sub reports. The master section is grouped by a column called "ProductCode".
In the first subreport, I'm trying to use the footer totals in the masterdata band for percentage calculations, eg, (<Col1>/<Total Col1>) * 100 and place this column adjacent to Col1.
In the footer band's OnBeforePrint, I type the code -
set(<Query1."BookingValue">,sum(<Query2."Bookings">)) ; (I'm assigning the sum(bookings) to Bookingvalue of the first query from where this sub report is being called)
Then I add a memo object in the masterdata band next to the bookings column. In the OnBeforePrint event of the new memo, I write the following code -
memo89.text:=formatfloat('#0.0',(<Query2."Bookings">/get(<Query1."BookingValue">))*100);
But When I run the preview, I get the following error :
"Could not convert variant of type(null) into type(OleStr)" OR sometimes
"Could not convert variant of type(null) into type(Double)" .
I used the same method for another report and it works, but I'm getting and error for this one. Can someone please let me know where I'm going wrong,it's very important.
Thanks & Regards,
Sriram
Comments
then you write your code to replace the memos text in an if engine.finalpass pass block.
Hi,
Thanks for your post. But the report has the "double pass" option enabled. It would be great if u tried to simulate it.
Thanks & Retgards,
Sriram
then make sure that the result of expression calculation is in the correct form for the property you are
trying to place it in.
since you are using the text property of the memo it needs to be a string.
to do the calculation, values must be in the correct numeric format. so in some instances you may need to declare typed vars in the procedure and the correct functions to do the calc before converting to a string to be placed in the memos text.
sample from total in groupheader demo report.
procedure Band7OnBeforePrint(Sender: TfrxComponent);
begin
Set(<Sales."Company">, Sum(<Sales."Qty">*<Sales."List Price">));
// gathered value and stored in array
end;
procedure Memo4OnBeforePrint(Sender: TfrxComponent);
// you may need to declare typed vars here to perform calcs
begin
if Engine.FinalPass then
// write code here to retreive values into vars and perform calcs
// place string in memo text.
Memo4.Text := 'Sum: ' + Format('%2.2m',[Get(<Sales."Company">)]);
// format function returned a formatted string,from the array argument so it could be concantenated to
// the lead string
end;
also make sure you arenot trying to divide by 0.