Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / January 2007

Tip: Looking for answers? Try searching our database.

constraint programming

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pieter - 25 Jan 2007 12:06 GMT
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
Phill W. - 25 Jan 2007 13:12 GMT
> 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.
Nick Malik [Microsoft] - 29 Jan 2007 18:22 GMT
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'.

Signature

--- 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.
--

> Hi,
>
[quoted text clipped - 37 lines]
>
> Pieter

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.