Control Array

 

Today I provide another example for yesterday   VB question under the Yahoo! Answer section that goes like this "How do I make an array of option buttons so that they all do different stuff?what i mean is : I put 1 option button into a frame. I then copied it and got prompted with: "do you want to make a control array"  I said yes then I put 9 different buttons into the frame and they are option1(0) option1(1) option1(2) option1(3) .... option1(8) now when I double click one of them it takes me to the code but no matter which one I click, it brings me to the same sub within the code... how do  I make it so each option button does something different?." . He actually asked about how to click one one option button so that only the relevant picture appears and all the other pictures remain  invisible. Below is the solution for the above question:

 

Private Sub Option1_Click(Index As Integer)
Dim i As Integer
Select Case Index
Case 0

For i = 0 To 9
Picture1(i).Visible = False
Next
Picture1(0).Visible = True

Case 1
For i = 0 To 9
Picture1(i).Visible = False
Next
Picture1(1).Visible = True

Case 2
For i = 0 To 9
Picture1(i).Visible = False
Next
Picture1(2).Visible = True

Case 3
For i = 0 To 9
Picture1(i).Visible = False
Next
Picture1(3).Visible = True

.
.
.
.
Case 9
For i = 0 To 9
Picture1(i).Visible = False
Next
Picture1(9).Visible = True

End Select
End Sub

 

The Design Screen Shot

The run time screen shot

 

 

 

 

 

 

 [Back to VBToday]