OnBeforePrint
EPML
UK
H all,
I have a MemoView called Memo14 in the Page Footer of my report that I am trying to display a page sub total within.
When the MemoView conatains [SUM(<frxIBODataset1."AMOUNT">,MasterData1)] within the page, it displays the page sub total correctly.
However when I have a function called MonthSubTotal in the MemoView as [MonthSubTotal] and have the following in the code script, it does not work...
var
lMonthSubTotal: Extended;
function MonthSubTotal: String;
begin
Result := FloatToStr(lMonthSubTotal);
end;
procedure Memo14OnBeforePrint(Sender: TfrxComponent);
begin
lMonthSubTotal := SUM(<frxIBODataset1."AMOUNT">,MasterData1);
end;
begin // main code
lMonthSubTotal := 0;
end.
I get the following error:
Could not convert variant of type (Null) into type (Double)
Can anyone explain to me why it works with the SUM code embedded in the MemoView and not in the script code and how I need to fix the script code please.
Many thanks for any help in advance.
I have a MemoView called Memo14 in the Page Footer of my report that I am trying to display a page sub total within.
When the MemoView conatains [SUM(<frxIBODataset1."AMOUNT">,MasterData1)] within the page, it displays the page sub total correctly.
However when I have a function called MonthSubTotal in the MemoView as [MonthSubTotal] and have the following in the code script, it does not work...
var
lMonthSubTotal: Extended;
function MonthSubTotal: String;
begin
Result := FloatToStr(lMonthSubTotal);
end;
procedure Memo14OnBeforePrint(Sender: TfrxComponent);
begin
lMonthSubTotal := SUM(<frxIBODataset1."AMOUNT">,MasterData1);
end;
begin // main code
lMonthSubTotal := 0;
end.
I get the following error:
Could not convert variant of type (Null) into type (Double)
Can anyone explain to me why it works with the SUM code embedded in the MemoView and not in the script code and how I need to fix the script code please.
Many thanks for any help in advance.
Comments
again read the user manual chapter on script and on aggregates.
BTW the function doesn't make any sense since you can set the display format of the memo.
Thanks for the reply gordk.
I have read the manual over and over today on both chapters and I cant see what I am doing wrong. [img]style_emoticons/<#EMO_DIR#>/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> Why is SUM(<frxIBODataset1."AMOUNT">,MasterData1); returning null? Can you give me some pointers please or educate me as to how to get my script code to work please. Can you explain why the function wont work? I cannot see why not - if I can just get the SUM to work then all should be good. Many thanks in advance.[/img]
typical when not using aggregate
var monthtotal: extended //initialize or reset to 0 in approp event.
obp of masterdataband
if month(<dsname."Datefield">) = 11 then monthtotal := monthtotal +<dsname."amount">;
You keep feeding us little bits which may be taken out of context.
is this a nested group report? or just master detail
Thanks again for your help.
It is simply a very simple Master detail report - one header, one footer and a masterdata.
Sorry I have been trying to give as much info as possible.
I believe I have just got it to work now with some minor changes...
var
lMonthSubTotal: String;
function MonthSubTotal: String;
begin
Result := lMonthSubTotal;
end;
procedure Memo14OnBeforePrint(Sender: TfrxComponent);
begin
lMonthSubTotal := (FloatToStr(SUM(<frxIBODataset1."AMOUNT">,MasterData1)));
end;
begin // main code
lMonthSubTotal := '';
end.
and Memo14 looks like [MonthSubTotal] in the Page view now and this seems to display the page sub total [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Is this the right way to do things? Many thanks again.[/img]
var
lMonthSubTotal: String;
function MonthSubTotal: String;
begin
Result := lMonthSubTotal;
end;
procedure Memo14OnBeforePrint(Sender: TfrxComponent);
begin
lMonthSubTotal := (FloatToStr(SUM(<frxIBODataset1."AMOUNT">,MasterData1)));
end;
seems like a bunch of wasted steps to me.
sample
var
curmonth:integer,
Monthsubtotal: extended;
begin
curmonth := month(now);
end.
//code in obp event of masterdata band;
if month(<datasetname."orderdate">) = curmonth then
monthsubtotal := monthsubtotal + <datasetname."Amount">;
footermemo contains[monthsubtotal]
Ok things weren't working as I expected, so using your example gordk, which is what I needed as I am still not getting anywhere with the manuals, I now have it working as I want [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> var PreviousMonth: Integer; MonthSubTotal: Extended; procedure frxReport1OnStartReport(Sender: TfrxComponent); var myDate: TDateTime; myYear, myMonth, myDay: Word; begin myDate := <frxIBODataset1."BANKDATE">; DecodeDate(myDate, myYear, myMonth, myDay); PreviousMonth := myMonth; end; procedure MasterData1OnBeforePrint(Sender: TfrxComponent); var myDate: TDateTime; myYear, myMonth, myDay: Word; begin Set('Balance',(<Balance> + <frxIBODataset1."AMOUNT">)); Memo28.Text := 'Month Sub Total'; myDate := <frxIBODataset1."BANKDATE">; DecodeDate(myDate, myYear, myMonth, myDay); if myMonth <> PreviousMonth then begin Memo28.Text := 'Month Total'; Engine.NewPage; MonthSubTotal := 0; end; PreviousMonth := myMonth; MonthSubTotal := MonthSubTotal + <frxIBODataset1."AMOUNT">; end; begin //main code MonthSubTotal := 0; end. Masterdatamemo contains [Balance] Footermemo contains [MonthSubTotal] Each time the month from the returned data is changed, there is a new page and the Month Sub Total is reset to start calculating again. This is what I needed! Many thanks again gordk for your help[/img]