• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

Dynamic Control Creation

I am using this code to create x numer of command buttons - I will add positioning etc

for i = 1 to x
 load CmdBut(i)
 CmdBut(i).enabled = 1
next i


But how do I 'click' the newly created button?

Private Sub Command(i)_Click()

'Do something

End Sub


0
NessieB
Asked:
NessieB
  • 2
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
The code for the click handler would be:

    Private Sub CmdBut_Click(Index As Integer)

    End Sub

So if you wanted to click the new button it would be:

    Call CmdBut_Click(i)

0
 
NessieBAuthor Commented:
Really??? that simple!

so if I knew I would have a maximum of 100 buttons then to access any button I could use

         Private Sub CmdBut_Click(Index As Integer)

            if index <= 100 then

              My Code Here

            endif

         End Sub

is that right ?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Yes...the "Index" parameter tells you which button in your control array was clicked.
0
 
NessieBAuthor Commented:
Thanks Very Much!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now