Topic: calc

I just cannot workout what the heck is wrong with the script below?


procedure CalculateTotal;

begin
    frmTest.edNetTotal.Value := (frmTest.edSubTotal.value + frmTest.edDelivery.Value) - (frmTest.edDiscount.Value); //NetTotal calcs ok

    frmTest.edGrossTotal.Value := frmTest.edNetTotal.Value + frmTest.edTaxTotal.Value;  // GrossTotal cals is not working
end;


 procedure frmTest_edDiscount_OnChange (Sender: string);
begin
    CalculateTotal;
end;

procedure frmTest_edDelivery_OnChange (Sender: string);
begin
    CalculateTotal;
end;


begin

end.
Post's attachments

Attachment icon Calc and tGrid Test.zip 5.46 kb, 359 downloads since 2016-12-11 

Adam
God... please help me become the person my dog thinks I am.

2 (edited by mathmathou 2016-12-12 02:11:06)

Re: calc

Hello Adam,


Nothing is wrong with your calculation, you just forgot to trigger the calculation on edTaxTotal field.

Add this to your script and this should be fixed

procedure frmTest_edTaxTotal_OnChange (Sender: string);
begin
    CalculateTotal;
end;

Cheers


Mathias


PS : I also corrected tab order and disabled net total field (like read only but better I find) tos suite my taste smile
I'm a bit maniac and I don't like tabs in the wrong order smile smile smile

Post's attachments

Attachment icon Calc and tGrid Test corrected.zip 334.86 kb, 415 downloads since 2016-12-12 

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: calc

and for edsubTotal

procedure frmTest_edsubTotal_OnChange (Sender: string);
begin
    CalculateTotal;
end;
Dmitry.

4 (edited by AD1408 2016-12-13 14:00:14)

Re: calc

Thanks a lot guys........


I'm trying to copy one field value to another.


https://s29.postimg.org/v5oz8iunb/copydelivcost.png


I like to copy Deliv Cost field value (on form calc) into Plus Deliv Cost field to include in calc as seen on the image above.

I have tried

procedure CalculateTotal;
frmTest.edTestDelivCostPlus.Value := frmTest.edTestDelivCost.Value;

The above script crashes the app on compile?


ps/. I know there is an issue on tax calc as items tax rates can be different. I think I'll have to calc discount separately and copy similar to deliv cost. However, suggestions are welcome.

Post's attachments

Attachment icon copydelivcost.png 5.61 kb, 218 downloads since 2016-12-13 

Adam
God... please help me become the person my dog thinks I am.

Re: calc

AD1408 wrote:

Thanks a lot guys........


I'm trying to copy one field value to another.


I like to copy Deliv Cost field value (on form calc) into Plus Deliv Cost field to include in calc as seen on the image above.

I have tried

procedure CalculateTotal;
frmTest.edTestDelivCostPlus.Value := frmTest.edTestDelivCost.Value;

The above script crashes the app on compile?


I think I've sorted it out. It wasn't the script above casing the issue but it was event procedure associated:


procedure frmTest_edTestDelivCostPlus_OnChange (Sender: string);
begin
    CalculateTotal;
end;

After commenting out the event procedure it worked OK. I was kind of asking calc total of nothing it seems.

Adam
God... please help me become the person my dog thinks I am.