Formula

Posting This Question Again As I Didnt Get The Answer So Far. plz ans me I have a table named Table1 There are 4 fields in it. 1. Length (Integer) 2. Widht (Integer) 3. Formula (text) 4. Area (Decimal) I will input like this length = 10 width = 20 Formula = length * (width/12) While Inserting in table it will read formula & store value of Area = 16.33 means it will take any input (formula) in formula field. evaluate it & then store the value in area field the formulas can be any thing like this l+w l-w l+(w*100) l/10 + ((w/12)+20) Please Help Me Soumya

Hi, In Account Schedule Column Layout you can specify formula. Please have a look on that.

Hi Soumya, I can think of a few solutions: A) you could build your own codeunit to give a formula in text, the parameters, parse the formula and return the result… It is not easy… B) build a DLL that does this work and call it from cal. That way you can use other development tool, like delphi or VB that is easier to handle such cases and already has components that can do all the work for you. C) Use a dos program that calculates expressions and execute it giving the expression and its values… D) Use predefined formulas and in the OnValidate Routine of each field check which formula is active and execute pre-written code to do the calculation… I suggest the last solution, but if you want to have dynamic user defined formulas then you should use suggestion A or B.

Hi, This doesn’t really pertain to your original question, but I thought I would give you a warning about something you are doing. I just finished a project a month ago that I too had a table with the fields “Length” and “Width.” I had some strange things happen to me on various forms when setting the value of “Width” because “WIDTH” is a property of text box controls, label controls, etc.!!! In one form, the width of a text box kept getting changed because of some code on the form. I would change the width property in design mode and then the width would change at run time! I guess the lesson of this is that it might be a good idea to avoid using variable or field names that are the same as property names. Best of luck, Mark.

Hi Biswas, You could create separate fields to store parameters for example A, B, C, D, E … and then a field called formula which references to you column names. This will be more effiecient than having a user defined text value to enter formula. Some of the processing by a Evaluate and string functions will usually be very slow and the user would then prefer the do the calculation manually with a calculator and key them in. IN the proposed approach you will need to limit the formula to some limited number of Parameters. The similar approach is used in Account Schedules column layout. Where they reference to Row No. or Column Number to calulate. --------------------------------------------------------------- Some things are easier said than Done.

I think it’s fairly straight forward to write your own calculator parser to deal with the formula. Just read the formula from left to right and process each token. No different than the sequence of strings you would type into a calulator. That said, it would be easier to parse if the fieldnames were one letter only, or you have to add pre-proceesing to your formula, like replacing LENGTH with L. You’ll have to add a stack with push and pop operations to handle the parenthesis, or you can reorganize the way you type in formulas, such as: l+w → (+ l w) l-w → (- l w) l+(w100) → (+ l ( w 100)) l/10 + ((w/12)+20) → (+ (/ l 10) (+ (/ w 12) 20)) l + (w ^ 2) → (+ 1 (^ w 2)) (Anyone who as ever programmed LISP knows what I mean). By placing the operator before the operands makes the pre processing real easy. If it rains on the weekend, I’ll try to put something together. -john

Thank You. I will try this out

quote:

Hi, In Account Schedule Column Layout you can specify formula. Please have a look on that.
Originally posted by Rajeshj - 2004 Nov 17 : 07:36:43

You will find this in CU8 - EvaluateExpression.