-
Aug 2nd, 2016, 02:57 PM
#1
Thread Starter
Hyperactive Member
[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?
-
Aug 2nd, 2016, 04:27 PM
#2
Lively Member
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
Last edited by On Error Try Again; Aug 2nd, 2016 at 04:47 PM.
-
Aug 2nd, 2016, 04:53 PM
#3
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:
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
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|