how to stop user adding number to NumericUpDown after it reach a vlaue

43 Views Asked by At

I have 10 NumericUpDowns. I want them when to reach the limit of 14 and then the last NumericUpDown the user clicked only can be decreased or stay the same after the msgbox display, I set the limit to each is 4

Private Sub Chkval()
        Dim storeval(11) As Integer
        storeval(0) = NumericUpDown1.Value
        storeval(1) = NumericUpDown2.Value
        storeval(2) = NumericUpDown3.Value
        storeval(3) = NumericUpDown4.Value
        storeval(4) = NumericUpDown5.Value
        storeval(5) = NumericUpDown6.Value
        storeval(6) = NumericUpDown13.Value
        storeval(7) = NumericUpDown14.Value
        storeval(8) = NumericUpDown18.Value
        storeval(9) = NumericUpDown19.Value
        If storeval.Sum > 14 Then
            MsgBox("ok")
        End If
    End Sub
1

There are 1 best solutions below

1
cezary On

Just hook all the 10 numericupdowns' ValueChanged event to a single event handler and in that handler check if the sum of all the values has exceeded 14. If so, then decrease the sender numericupdown's value so that the sum = 14.