Solved
How can I split the Maximum Value of a NumericUpDown Control over several controls?
Posted on 2007-08-03
This is something that, when I first undertook it, I thought would be extremely easy. Now, I've been working on it for 14 hours straight, I've tried dozens, if not hundreds of different ways to accomplish it, and it's still not working. I'm about ready to throw my computer at something big and solid.
Ok, now that I'm done ranting (for now), here's my problem. I have eight NumericUpDown Controls. Each of these controls has a maximum value of 100. However, only one control can actually have a value of 100. (If this is confusing, let me know. It's confusing me as I try to type it.) All of the controls can have a value of 60, but then there are only 40 points which can be split between the controls. (i.e. on control's value = 100, and all other controls' values = 60, or two controls = 80, and all other controls = 60, or one control = 65, one control = 70, one control = 75, and five controls = 60 with 10 points left to distribute.) The maximum value does not have to be met. I can have 5 controls with a value of 0, and one control with a value of 10 if I want.
The numberupdown controls names are: WWlvl, CClvl, GSlvl, BSlvl, BClvl, LClvl, Cooklvl, and Alclvl
The closest I've come to accomplishing this so far has been to have the numericupdowns call the following procedure on the ValueChanged event:
Private Sub LevelValues()
Dim MaxValue As Integer = 40
If GSlvl.Value <= 60 And WWlvl.Value <= 60 And BSlvl.Value <= 60 And Cooklvl.Value <= 60 And Alclvl.Value <= 60 _
And BClvl.Value <= 60 And LClvl.Value <= 60 And CClvl.Value <= 60 Then
gslvl.
GSlvl.Maximum = 100
WWlvl.Maximum = 100
BSlvl.Maximum = 100
Cooklvl.Maximum = 100
Alclvl.Maximum = 100
BClvl.Maximum = 100
LClvl.Maximum = 100
CClvl.Maximum = 100
Else
If GSlvl.Value > 60 Then
WWlvl.Maximum = MaxValue - (100 - GSlvl.Value)
BClvl.Maximum = 60 + MaxValue
BSlvl.Maximum = 60 + MaxValue
LClvl.Maximum = 60 + MaxValue
CClvl.Maximum = 60 + MaxValue
Alclvl.Maximum = 60 + MaxValue
Cooklvl.Maximum = 60 + MaxValue
End If
If WWlvl.Value > 60 Then
MaxValue = MaxValue - (100 - WWlvl.Value)
GSlvl.Maximum = 60 + MaxValue
BClvl.Maximum = 60 + MaxValue
BSlvl.Maximum = 60 + MaxValue
LClvl.Maximum = 60 + MaxValue
CClvl.Maximum = 60 + MaxValue
Alclvl.Maximum = 60 + MaxValue
Cooklvl.Maximum = 60 + MaxValue
End If
If BClvl.Value > 60 Then
MaxValue = MaxValue - (100 - BClvl.Value)
WWlvl.Maximum = 60 + MaxValue
GSlvl.Maximum = 60 + MaxValue
BSlvl.Maximum = 60 + MaxValue
LClvl.Maximum = 60 + MaxValue
CClvl.Maximum = 60 + MaxValue
Alclvl.Maximum = 60 + MaxValue
Cooklvl.Maximum = 60 + MaxValue
End If
If BSlvl.Value > 60 Then
MaxValue = MaxValue - (100 - BSlvl.Value)
WWlvl.Maximum = 60 + MaxValue
BClvl.Maximum = 60 + MaxValue
GSlvl.Maximum = 60 + MaxValue
LClvl.Maximum = 60 + MaxValue
CClvl.Maximum = 60 + MaxValue
Alclvl.Maximum = 60 + MaxValue
Cooklvl.Maximum = 60 + MaxValue
End If
If LClvl.Value > 60 Then
MaxValue = MaxValue - (100 - LClvl.Value)
'WWlvl.Maximum = 60 + MaxValue
'BClvl.Maximum = 60 + MaxValue
'BSlvl.Maximum = 60 + MaxValue
'GSlvl.Maximum = 60 + MaxValue
'CClvl.Maximum = 60 + MaxValue
'Alclvl.Maximum = 60 + MaxValue
'Cooklvl.Maximum = 60 + MaxValue
End If
If CClvl.Value > 60 Then
MaxValue = MaxValue - (100 - CClvl.Value)
WWlvl.Maximum = 60 + MaxValue
BClvl.Maximum = 60 + MaxValue
BSlvl.Maximum = 60 + MaxValue
LClvl.Maximum = 60 + MaxValue
GSlvl.Maximum = 60 + MaxValue
Alclvl.Maximum = 60 + MaxValue
Cooklvl.Maximum = 60 + MaxValue
End If
If Cooklvl.Value > 60 Then
MaxValue = MaxValue - (100 - Cooklvl.Value)
WWlvl.Maximum = 60 + MaxValue
BClvl.Maximum = 60 + MaxValue
BSlvl.Maximum = 60 + MaxValue
LClvl.Maximum = 60 + MaxValue
CClvl.Maximum = 60 + MaxValue
Alclvl.Maximum = 60 + MaxValue
GSlvl.Maximum = 60 + MaxValue
End If
If Alclvl.Value > 60 Then
MaxValue = MaxValue - (100 - Alclvl.Value)
WWlvl.Maximum = 60 + MaxValue
BClvl.Maximum = 60 + MaxValue
BSlvl.Maximum = 60 + MaxValue
LClvl.Maximum = 60 + MaxValue
CClvl.Maximum = 60 + MaxValue
GSlvl.Maximum = 60 + MaxValue
Cooklvl.Maximum = 60 + MaxValue
End If
End If
End Sub
This sub seems to work ok at first, If I have one control at 100, and change another to 61, the first one drops to 99. but then it doesn't drop to 98 until the second is at 63, which exceeds the 100 total.
I know there has to be an easier way to do this, and probably with a lot less code. I'm very open to suggestions right now.
Thank you,
~Skid