[RESOLVED] To understand button click event.-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] To understand button click event.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    470

    Resolved [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?

  2. #2
    Lively Member
    Join Date
    Feb 2008
    Posts
    69

    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.

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    3,040

    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:
    Name:  ControlArray.gif
Views: 48
Size:  7.7 KB

    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

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.