Skip to main content
edited body
Source Link
Enigmativity
  • 116.8k
  • 11
  • 100
  • 179

Here is how I do it to maintain strong-typing.

Dim chkBrs = { chkBr1, chkBr2, chkBr3, chkBr4, chkBr5, chkBr6 }
For i As Integer = 10 To chkBrs.Length - 1
    chkBrs(i).Visible = True
    chkBrs(i).Text = "Applicant " & i + 1
Next

You can find controls by name, but this is the .Name property and not the name of your variable in your code. If you end up with controls that have different names to the variable then that code wouldn't work. The approach I use will continue to work.

Here is how I do it to maintain strong-typing.

Dim chkBrs = { chkBr1, chkBr2, chkBr3, chkBr4, chkBr5, chkBr6 }
For i As Integer = 1 To chkBrs.Length - 1
    chkBrs(i).Visible = True
    chkBrs(i).Text = "Applicant " & i
Next

You can find controls by name, but this is the .Name property and not the name of your variable in your code. If you end up with controls that have different names to the variable then that code wouldn't work. The approach I use will continue to work.

Here is how I do it to maintain strong-typing.

Dim chkBrs = { chkBr1, chkBr2, chkBr3, chkBr4, chkBr5, chkBr6 }
For i As Integer = 0 To chkBrs.Length - 1
    chkBrs(i).Visible = True
    chkBrs(i).Text = "Applicant " & i + 1
Next

You can find controls by name, but this is the .Name property and not the name of your variable in your code. If you end up with controls that have different names to the variable then that code wouldn't work. The approach I use will continue to work.

Source Link
Enigmativity
  • 116.8k
  • 11
  • 100
  • 179

Here is how I do it to maintain strong-typing.

Dim chkBrs = { chkBr1, chkBr2, chkBr3, chkBr4, chkBr5, chkBr6 }
For i As Integer = 1 To chkBrs.Length - 1
    chkBrs(i).Visible = True
    chkBrs(i).Text = "Applicant " & i
Next

You can find controls by name, but this is the .Name property and not the name of your variable in your code. If you end up with controls that have different names to the variable then that code wouldn't work. The approach I use will continue to work.