Stuffing executable code in a memo field is an unholy hack. It's a PITA to parse, debug, or cross-reference. Compilers don't catch simple syntax errors, error-handlers can't tell you the line of code, cross-reference won't flag the use of the variables.
If you've got an object oriented system, you use a strategy pattern. If it's PRG based, you use a switch: If Customer.PricingStrategy = 1 DO Strategy1 ELSE DO Strategy2 ENDIF If you're really determined to make this as obscure as possible, create the programs, compile them into FXPs and stuff them into memo fields to pull out and StrToFile() at runtime to launch the calculation. No, seriously, don't do that. On Tue, Nov 17, 2015 at 7:52 PM, Ken Dibble <[email protected]> wrote: > >> Here's the twist. My current code is a multi-line segment. Something >> like >> >> Cost = Qty * UnitCost >> Tax_Cost = (Cost * Tax_Rate/100) >> SubTotal = Cost + Tax >> Overhead_Cost = SubTotal * (Overhead_Rate/100) >> Markup_Cost = (SubTotal + Overhead_Cost) * (Markup_Rate/100) >> Total_Cost = SubTotal + Overhead_Cost + Markup_Cost > > > Yup, storing those in a memo field would work just fine. I do this stuff all > the time in my metadata-driven visual classes. > > I would use ALINES() to get each line into an array, and then tack on an > extra column for the results of each calculation. As Joel says, then you > could assemble a text string that can run as a macro. It should be pretty > straightforward to parse each line and substitute the appropriate field data > into the line in place of the field names. Since it's all numbers and > operators, you don't have to mess around making sure you're quoting or not > quoting things as needed. You would just need to TRANSFORM() the numeric > data as it comes out of the table. > > Now you can loop through the array and do something like: > > LOCAL CurrentFormula > > CurrentFormula = LTRIM(SUBSTR(aArray(x,1),AT(aArray(x,1),"=") > > aArray(x,2) = &CurrentFormula > > INSERT INTO curReportData (Variable,Result) VALUES > (LEFT(aArray(x,1),,AT(aArray(x,1),"=") - 2),aArray(x,2)) > > Something like that anyway. Not tested. Be very afraid. You could preprocess > the lines a little more, add another column to the array to store the name > of the results variable so you aren't SUBSTR-ing and AT-ing all over the > place in the loop code, etc. > > Anyway, what I'd do would end up looking something like that. > > Ken Dibble > www.stic-cil.org > > > [excessive quoting removed by server] _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/CACW6n4v3xa-n3=cCyKAcbrwr3h2r__W0=us5evwo9hohbi7...@mail.gmail.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

