or you can do a:
Dim checkboxes() As CheckBox = New CheckBox() {CheckBox1, CheckBox2}
For Each chk As CheckBox In checkboxes
chk.Checked = True
Next
Put as many check boxes in the array.
Hope that helps.
Abubakar.
http://joehacker.blogspot.com
"Mason" wrote:
> I want to do a for loop through 45 check boxes, whose names are
> CheckBox1 ... CheckBox 45. I'd like to do something like this:
>
> Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnNext.Click
>
> Dim i As Integer
> Dim strCheckBox As String
>
> For i = 1 To 45
> strCheckBox = "CheckBox" & i
> test = strCheckBox
> If '***strCheckBox.Checked=True***
> MsgBox(strCheckBox & "=True")
> End If
> Next
> End Sub
>
> I can't figure out how to reference a checkbox when I have only its
> name. It should be a fairly simple piece of code, but I just can't
> find it. Any help would be appreciated.
>
> Thanks,
>
> MW
>