Flowfield based on 2 other flowfields ?

Hi I have 2 flowfields in a table: one calculates an amount, the other calculates a number. I want to have a third flowfield that calculates the division of these 2 flowfields. Is there a way to do this ? Thanks in advance

That’s not possible with a flowfield. At least not in version 3.6. You’ll have to program it…

This is not a FlowField, since there is nothing to “flow” from. You need to rethink what you are doing. What I am guessing is that you need to calculate the Average Unit Cost or price of some lines. ([:(!] Of course if it wasn’t top secret, you might have posted details of what you are trying to achieve). Anyway… what you need to do is to go to the table where you have the flow fields, and create a new function like this… **DivideNumber::Decimal(Num1:Dec,Num2:Dec)** If Num2 = 0 then exit(0); exit(round(num1 / num2,0.00001)); Then in your report or form or what ever, you have the two flow fields, Say TotalAmt and TotalQty, in the Source Expresion for the Control that you want to display the average, put: DivideNumber(TotalAmt,TotalQty)

A possible pitfall can be: On the form or report where you want to add the function “DivideNumber(TotalAmt,TotalQty)”, the flowfields TotalAmt and TotalQty must be present. If they arent’s present, they aren’t calculated and you’ll always get back 0.

Yes that’s obvious, if the fields are not calculated then you will need to add calcfields before calling the function. There is a property on reports and forms, “CalcFields”, but since it does not work, it won’t help you. if you wnat you could change the function to include the calcfields etc. but then the function would be specific to just that particular requirement. The solution above is more generic. And since I have no idea (since it is your secret) of what you are really trying to achive, there isnot much way I can help more.

In this case, I would probably go with the “non-generic” solution. You could just make it look as if it were a field; AverageCost::Decimal CALCFIELDS(TotalCost,TotalQty); IF TotalQty <> 0 THEN EXIT(TotalCost/TotalQty) ELSE EXIT(0); Then basically you can just put AverageCost as a field on your form/report. This is just my personal preference (which rarely, but every so often differs from David’s [:D])

You could put the two solutions together and put “CALCFIELDS(TotalCost,TotalQty);” in the fuction “DivideNumber”. And don’t send any parameters with it.

No Tino, Chris is right, you cna’t just add the Calcfields to the original function, since it is field specific. I almost always use the code that Chris suggests here, its just that in this case you don’t want to tell us what you are doing, so I can’t give you a specific solution, so I gave you a general one.

I solved it by adding a textbox that contains the result of the division of the two flowfields to the tablebox, and stored the calculation in the aftergetrecord-trigger of the form. Perhaps I was not very clear in my question. I only needed a way to present the result of the division of those 2 existing flowfields in the tablebox. Thanks for the tips.

don’t forget to handle divide by zero.

I did, thanks :slight_smile: