PC Review


Reply
Thread Tools Rate Thread

constraint programming

 
 
Pieter
Guest
Posts: n/a
 
      25th Jan 2007
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


 
Reply With Quote
 
 
 
 
Phill W.
Guest
Posts: n/a
 
      25th Jan 2007
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 _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.
 
Reply With Quote
 
Nick Malik [Microsoft]
Guest
Posts: n/a
 
      29th Jan 2007
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.
--
"Pieter" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: constraint programming Nick Malik [Microsoft] Microsoft VB .NET 0 29th Jan 2007 06:22 PM
constraint programming Pieter Microsoft Dot NET Framework 2 29th Jan 2007 06:22 PM
constraint programming Pieter Microsoft Dot NET 2 29th Jan 2007 06:22 PM
Help Programming Limit Constraint Suz84 Microsoft Excel Programming 5 2nd Aug 2006 03:06 PM
Help Programming Limit Constraint Suz84 Microsoft Excel Programming 0 2nd Aug 2006 01:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:46 AM.