rp
asked on
Vb.net dynamic formulas in runtime
Hi,
What is the best way to calculate dynamic formulas in vb.net.
I have some products with some similar attributes. But attributes can depend on previous calculations and change from product to product. This is for a quality control.
For ex.
Product A, for ex an apple
A - if product is very mature then decrease 10% in total weight (A)
B - If product is also with external defects then decrease 15% on the price. In this case not over the total weight, but total weight - 10%. --> (A) result
Other products has some diferences
best reagrds
What is the best way to calculate dynamic formulas in vb.net.
I have some products with some similar attributes. But attributes can depend on previous calculations and change from product to product. This is for a quality control.
For ex.
Product A, for ex an apple
A - if product is very mature then decrease 10% in total weight (A)
B - If product is also with external defects then decrease 15% on the price. In this case not over the total weight, but total weight - 10%. --> (A) result
Other products has some diferences
best reagrds
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
The problem is that I do not intend to have a rigid structure at the code level. I wanted to create a formula that would be stored in a database and run in runtime mode. For they are several similar products but the calculations differ between each ones.
best regards
The problem is that I do not intend to have a rigid structure at the code level. I wanted to create a formula that would be stored in a database and run in runtime mode. For they are several similar products but the calculations differ between each ones.
best regards
have a look at my article then
>>For they are several similar products but the calculations differ between each ones.
If product type X always has a, b, c but product type Y always has a,d,h and product type Z always has c,d,h..... then what I suggested is a simple way to go. (Also easy to debug)
However if on the second tuesday in a month with 30 days you want a,b,c but otherwise if the operator is called Fred then it is p,q,r.... then allowing the user to type a formula (as Eric suggests) is the only way forward.
If product type X always has a, b, c but product type Y always has a,d,h and product type Z always has c,d,h..... then what I suggested is a simple way to go. (Also easy to debug)
However if on the second tuesday in a month with 30 days you want a,b,c but otherwise if the operator is called Fred then it is p,q,r.... then allowing the user to type a formula (as Eric suggests) is the only way forward.
Just a comment - VBCodeProvider unlike VB IDE doesn't use System namespace by default, so I suggest adding "Imports System" at the beginnig of the code to be compiled.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I notice you didn't consider my suggestion worthwhile but just how would you implement Kaufmeds implementation without a tree of if statements to determine just what to apply to the product?
In a console app, sure. But I think the benefit of this pattern is probably more realized in a user interface (i.e. with checkboxes/radio buttons).
True, I can see advantages of a pure OOP pattern under certain circumstances but the question looks rather more for automating some routine to me.
ASKER
Hi,
I chose the two answers (Moreau and käµfm³d ) because they seem to be the most flexible for what I intend to implement.
An if then structure, it's what I have now and is rigid.
best regards
I chose the two answers (Moreau and käµfm³d ) because they seem to be the most flexible for what I intend to implement.
An if then structure, it's what I have now and is rigid.
best regards
if (b) then price = price * .85
and so on. You are probably best drawing a tree structure on paper of what to do under what conditions then you have the logic map of which code path you require with if...then...else structures.