Control Array is no longer supported in VB.NET. Here is a method to handle situations that would have been handled with a control array:



Private Sub AllButtons_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click, btnTwo.Click, btnThree.Click

Dim i As Integer

Select Case sender.TabIndex

Case 0

txtWhich.Text = "You selected Button One"

Case 1

txtWhich.Text = "You selected Button Two"

Case 2

txtWhich.Text = "You selected Button Three"

End Select

For i = 0 To 2

If sender.TabIndex = i Then

txtCheck.Text = "The button was " & CStr(sender.TabIndex + 1)

End If


End Sub


Notice in the code above, I listed the click events for all three of the control buttons (btnOne, btnTwo and btnThree). This means that this code is executed no matter which one is clicked.

I then handled the code buttons in two ways. One was simply using the case structure to check and see which one was selected I did this by using the TabIndex so I had to make sure that the tab index for these was 0, 1 and 2. The other way also used the tab index. I compared it to an integer and if they matched then I printed out the tab index + 1 (obviously I could have printed out the integer but I wanted to use sender.TabIndex.


The image above shows clicking on Button Two.


I then went on to use the tag property instead of tab index, the following code could be used:


Select Case sender.tag

Case "one"

txtWhichTag.Text = "You selected Button One"

Case "two"

txtWhichTag.Text = "You selected Button Two"

Case "three"

txtWhichTag.Text = "You selected Button Three"

End Select


Note that the buttons were each given a tag. I used the words one, two and three.