[RESOLVED] To understand button click event.
I have a button and only one. I saw the code.
Code:
Private Sub cmdSomething_Click(Index As Integer)
Select Case Index
Case 0
Label1(8).Visible = True
Label1(7).Visible = True
Case 1
Label1(8).Visible = False
Label1(7).Visible = False
When I click the button the Index is always 0, how can I let the Index is 1?
Re: To understand button click event.
You have to click on cmdSomething(1).
You have only the 1st button of a button array so it has the array index of 0.
Since you only have one button then it's index is 0 by default. You need at least two buttons. So copy the button you have and paste it to make a second button and VB will make it cmdSomething(1). If you paste again you will get cmdSomething(2), etc etc
This is the simplest explanation I have. Others will drop in here later and give you the full details and explain how the entire control array system works
1 Attachment(s)
Re: To understand button click event.
Say zhshqzyc,
Yes, OnError has explained it. This is called a Control Array, which isn't to be confused with an Array-of-Controls. An Array of Controls would be something like an object variable declared as "Dim obj(1 To 5) As Object" and then using that to "Set" a bunch of control into it.
Whereas a Control Array is something you create at design time. In fact, every time you copy-paste a control on a form (that hasn't been previously arrayed), it attempts to create a Control Array for you with the following message:
Attachment 139897
By default, these Control Arrays start indexing at 0, just adding 1 for each new control. However, using the control's "index" property, you can index them any way you like, even skipping index values.
Regards,
Elroy