Re: [2005] Newbie question
you can use:
VB Code:
For Each ctrl As Control In Me.Controls
If TypeOf (ctrl) Is CheckBox And ctrl.Name.Substring(0, 4) = "name" Then
If DirectCast(ctrl, CheckBox).Checked = True Then MsgBox(ctrl.Name.Substring(4, 1) & " is checked")
End If
Next
Re: [2005] Newbie question
I tried to inster your text but got the following error
System.ArgumentOutOfRangeException was unhandled
Message="Index and length must refer to a location within the string.
Parameter name: length"
ParamName="length"
Source="mscorlib"
StackTrace:
it looks like it has to do with the (ctrl)
thanks,
Re: [2005] Newbie question
oh yeah sorry.
Made some modifications and it works now :)
VB Code:
For Each ctrl As Control In Me.Controls
If TypeOf (ctrl) Is CheckBox And ctrl.Name.Length >= 4 Then
If DirectCast(ctrl, CheckBox).Checked = True And LCase(ctrl.Name.Substring(0, 4)) = "name" Then MsgBox(ctrl.Name.Substring(4, 1) & " is checked")
End If
Next
Re: [2005] Newbie question
You can simply add the checkboxes onto the Handles clause, to allow them to call the same sub...
VB Code:
Private Sub chk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles chk.Click, chk2.Click, chk3.Click, chk4.Click
'your check code here
End Sub
The above code would be called anytime one of the checkboxes listed in the handles clause are clicked
Re: [2005] Newbie question
Thanks that is working. :wave: