constraint programming

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pieter

    #1

    constraint programming

    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 AmountNewCurren cy must be automaticly
    changed to AmountOldCurren cy * CurrencyRate
    but:
    When the user changes the in the TextBox the AmountNewCurren cy, the
    AmountOldCurren cy must be changed too (AmountNewCurre ncy / 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
    ArticleSellPric e accordingly).
    but:
    -When the TotalSellPrice is changed, the percentage has to be
    calculated automaticly, and the ArticleSellPric e of each article has to be
    changed proportionally

    - and many many more...


    Any help would be really appreciated,

    Thansk a lot in advance,

    Pieter


  • Phill W.

    #2
    Re: constraint programming

    Pieter wrote:
    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 _bRecursionBust er As Boolean = False

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

    If Not _bRecursionBust er Then
    _bRecursionBust er = True

    B = Value /2

    _bRecursionBust er = False
    End If

    End Set
    End Property

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

    If Not _bRecursionBust er Then
    _bRecursionBust er = True

    A = Value * 2

    _bRecursionBust er = 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.

    Comment

    • Nick Malik [Microsoft]

      #3
      Re: constraint programming

      I agree with Phil... update everything from each input to the function.

      IOW, have a 'recalculate_pa ge' 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_pa ge'.

      --
      --- 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.
      --
      "Pieter" <pieterNOSPAMco ucke@hotmail.co mwrote in message
      news:O12ZPlHQHH A.4424@TK2MSFTN GP06.phx.gbl...
      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 AmountNewCurren cy must be automaticly
      changed to AmountOldCurren cy * CurrencyRate
      but:
      When the user changes the in the TextBox the AmountNewCurren cy, the
      AmountOldCurren cy must be changed too (AmountNewCurre ncy / 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
      ArticleSellPric e accordingly).
      but:
      -When the TotalSellPrice is changed, the percentage has to be
      calculated automaticly, and the ArticleSellPric e of each article has to be
      changed proportionally
      >
      - and many many more...
      >
      >
      Any help would be really appreciated,
      >
      Thansk a lot in advance,
      >
      Pieter
      >

      Comment

      Working...