Answered Setting Max of nud boxes based on other nud boxes

Furiant

Member
Joined
Mar 26, 2008
Messages
5
Programming Experience
Beginner
Hi

I have a set of numeric up-downs (A, B, and C) whose values should add up to less than or equal to the value of another numeric up-down (Total).

Slots.gif


The Total value is the number of units available to be allocated between one or more Slots. Any combination of values in A, B, and C is valid, as long as A+B+C adds up to <= T. T itself can be any value.

My idea so far was this, but I can't get it to work at all.

VB.NET:
    Sub SetTotal(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nud_Total.ValueChanged, nud_SlotA.ValueChanged, nud_SlotB.ValueChanged, nud_SlotC.ValueChanged
        Dim toSpend As Integer = nud_Total.Value - (nud_SlotA.Value + nud_SlotB.Value + nud_SlotC.Value)
        If sender.Value <= toSpend Then
            nud_SlotA.Maximum = toSpend
            nud_SlotB.Maximum = toSpend
            nud_SlotC.Maximum = toSpend
        End If
    End Sub

Any advice would be appreciated.
 
Last edited:
Each NUD.Maximum is limited to current NUD.Value + toSpend.
 
Okay, that works :) Thank you.
 
Back
Top