constraint programming

  • Thread starter Thread starter Pieter
  • Start date Start date
P

Pieter

Hi,

How can I include contraints in VB.NET (Windows Forms, 2.0), using Objects
with Propertys?

I need several property's be recalculated when others change, but not in a
straightforward way: When A is changed, B has to change, but when B changes,
A has to change (or C or ...).
Untill now I added routines in the Set-Property that calculated the other
Property, but I'm loosing the overview, and I would have referred to have
all this rules centrally placed. Also, I'm kind of affraid of endless loops:
A changes B, B changes A, which changed B again etc etc...

Is there a way to do some kind of constraint programming in VB.NET? Or how
should I implement such a thing the best way?

I need constraints like this:
- When the Currency changes, the AmountNewCurrency must be automaticly
changed to AmountOldCurrency * CurrencyRate
but:
When the user changes the in the TextBox the AmountNewCurrency, the
AmountOldCurrency must be changed too (AmountNewCurrency / CurrencyRate).

- Another one: TotalBuyPrice = the total Price we pay for all the Articles
TotalSellPrice = The total Price at which we sell the Articles
Percentage: the percentage we add to the TotalBuyPrice to have a sudden
TotalSellPrice.
-> Is Percentage is changed, TotalSellPrice must be changed (and the
ArticleSellPrice accordingly).
but:
-> When the TotalSellPrice is changed, the percentage has to be
calculated automaticly, and the ArticleSellPrice of each article has to be
changed proportionally

- and many many more...


Any help would be really appreciated,

Thansk a lot in advance,

Pieter
 
Pieter said:
I need several property's be recalculated when others change, but not in a
straightforward way: When A is changed, B has to change, but when B changes,
A has to change (or C or ...).

I usually use a flag to prevent recursive calls, something like

Class X
Private _bRecursionBuster As Boolean = False

Property A() As ?
Set(Value as ?)

If Not _bRecursionBuster Then
_bRecursionBuster = True

B = Value /2

_bRecursionBuster = False
End If

End Set
End Property

Property B() As ?
Set(Value as ?)

If Not _bRecursionBuster Then
_bRecursionBuster = True

A = Value * 2

_bRecursionBuster = False
End If

End Set
End Property

End Class

With multiple properties, you make update everything from each property
and, with a bit of luck, you don;t get all that nasty endless looping.

HTH,
Phill W.
 
I agree with Phil... update everything from each input to the function.

IOW, have a 'recalculate_page' method that calculates every function, from
currency to total price. Then, when the user changes any of the inputs,
from locale to quantity, whatever, call 'recalculate_page'.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
Back
Top