Hi I have to create a groupbox with 6 checkboxes in it. When multiple checkboxes are clicked the checkbox with the higher int. value will be displayed in a label. How do I do this? How do I test the value of 6 checkboxes against the others and display the highest one that is checked? So if say checkbox1 is checked it will display a 1 in a label. So if multiple checkboxes are checked how can I just display the highest one?
1 Answer
Dim Chk As CheckBox
Dim i As Integer = 0
For Each Chk In GrpBox.Controls
If TypeOf (Chk ) Is CheckBox Then
If Chk .checked Then
If Chk .Tag > i Then i = Chk .Tag
End If
End If
Next
2 Comments
Aaron Warnke
Ok where do I put that code then, in one of the checkbox subs? Or in the main class?
Donny McCoy
You can put it in the form_load event thought I suggest that a better practice is to put it in your button's click event. I presume you have button or something similar that the user clicks to generate an event; at which point you will need to evaluate your checkboxes. Let me know if you have a different scenario.