[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 05:47 PM.

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

    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: 57
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
    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty where all my code has come from, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. 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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.