Topic: Invalid floating point operation on Calc.

I was trying to do simple win/loss percent calc.
With one calc it worked fine. When I added another win/loss calc on same page it returns "Invalid floating point operation"


The script below works with one calc on the same page:

procedure CalculateTotal;
begin
  Form1.edWinPercent.Value := Form1.edWinCount.value / (Form1.edWinCount.value + Form1.edLossCount.value) * 100;
  Form1.edLossPercent.Value := Form1.edLossCount.value / (Form1.edWinCount.value + Form1.edLossCount.value) * 100;
end;

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

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

The script below doesn't  work when added second calc. I've tried adding variables but couldn't get it working?

procedure CalculateTotal;
var
  WinPercent, LossPercent: Real;
  WinPercent2, LossPercent2: Real;

begin
  WinPercent:= Form1.edWinPercent.value;
  LossPercent:= Form1.edLossPercent.Value;
  WinPercent2:= Form1.edWinPercent2.value;
  LossPercent2:= Form1.edLossPercent2.Value;

    begin
    Form1.edWinPercent.Value := Form1.edWinCount.value / (Form1.edWinCount.value + Form1.edLossCount.value) * 100;
    Form1.edLossPercent.Value := Form1.edLossCount.value / (Form1.edWinCount.value + Form1.edLossCount.value) * 100;

    Form1.edWinPercent2.Value := Form1.edWinCount2.value / (Form1.edWinCount2.value + Form1.edLossCount2.value) * 100;
    Form1.edLossPercent2.Value := Form1.edLossCount2.value / (Form1.edWinCount2.value + Form1.edLossCount2.value) * 100;
    end;
end;

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

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


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

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

It may sound silly as to why I need more than one calc of same; on a same page but I needed. Each calc applies to different items on a same page.


Please see the attached sample project if needed:

Post's attachments

Attachment icon WinLoss Perc Calc.zip 4.45 kb, 446 downloads since 2017-02-14 

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

Re: Invalid floating point operation on Calc.

Change this script:

procedure CalculateTotal;
var
  WinPercent, LossPercent: Real;
  WinPercent2, LossPercent2: Real;

begin
  WinPercent:= Form1.edWinPercent.value;
  LossPercent:= Form1.edLossPercent.Value;
  WinPercent2:= Form1.edWinPercent2.value;
  LossPercent2:= Form1.edLossPercent2.Value;

    begin
    if (Form1.edWinCount.Value <> 0) and (Form1.edLossCount.Value <> 0) then
    begin
          Form1.edWinPercent.Value := Form1.edWinCount.value / (Form1.edWinCount.value + Form1.edLossCount.value) * 100;
          Form1.edLossPercent.Value := Form1.edLossCount.value / (Form1.edWinCount.value + Form1.edLossCount.value) * 100;
    end;

    if (Form1.edWinCount2.Value <> 0) and (Form1.edLossCount2.Value <> 0) then
    begin
    Form1.edWinPercent2.Value := Form1.edWinCount2.value / (Form1.edWinCount2.value + Form1.edLossCount2.value) * 100;
    Form1.edLossPercent2.Value := Form1.edLossCount2.value / (Form1.edWinCount2.value + Form1.edLossCount2.value) * 100;
    end;
end;
end;

Re: Invalid floating point operation on Calc.

Hi bemorhona-qt,


Thank you so much for your kind help..................


I couldn't think of including operator <>
I guess you assign a value so that it  knows the reference value to calculate the difference from?

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

Re: Invalid floating point operation on Calc.

yes, calculation is done when there is any digit or value so you have to show in the script if there is any number less or more than 0.