Formula calculation

  • Thread starter Thread starter VJ
  • Start date Start date
V

VJ

We have a form where there is a like 10-15 fields and it performs a length
formula calucation each time field value changes. Using validate event is
not a option as validate wont fire on Menu click and other events on toolbar
click. Right now we have it Value changed i.e entered into control (close to
a textchange) event. Is there a better way to do this.

Just really curious how excel is doing this really fast for complex
formulas, on cell value changes. One reason the formula evaluator is
complied and not interpeted code as in .NET, but would that be a big
difference maker?

VJ
 
..Net code *is* compiled (unless you are interpreting it yourself).
Personally I would bind the UI to an object model (even if that object-
model was UI specific), and simply update the formula property as
necessary and let the UI re-display it via notification. Actually,
myself I use a bespoke model that allows for notifications (via custom
PropertyDescriptors) to calculated values ala:

[Calculated("PropertyA","PropertyB")]
public int SomeFormula {
get {return PropertyA + SomeFunc(PropertyB);}
}

but that needs a lot of base libs that are too long to post here.
Alternatively, a simple model that implements INotifyPropertyChanged,
and simply fire the formula property when-ever you fire any of the
others...

Marc
 
(note you can set Bindings to update immediately rather than after
validation; this sounds like what you want)
 
VJ said:
We have a form where there is a like 10-15 fields and it performs a length
formula calucation each time field value changes. Using validate event is
not a option as validate wont fire on Menu click and other events on toolbar
click. Right now we have it Value changed i.e entered into control (close to
a textchange) event. Is there a better way to do this.

Just really curious how excel is doing this really fast for complex
formulas, on cell value changes. One reason the formula evaluator is
complied and not interpeted code as in .NET, but would that be a big
difference maker?

The traditional way is:
1) convert from string to list of opcodes and values
2) convert that from infix to postfix
3) evaluate

If you want to cheat, then call JavaScript Eval function from
your C# code.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top