creating buttons in the run time

By coding can I create Command buttons in the run time for example when type 10 in a text box, 10 command buttons will be created in the form…
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


If your using VB6 you can use the add method on the controls collection

Form1.Controls.Add "CommandButton"...

see help for exact parameters etc.


in vb4-5 etc.

use a control array
only create one commandbutton with index 0 at design time then at runtime

Load Command1(<NextIndex Value>)
Command1.Visible = True
set up properties and position

Hope this helps


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Yes you can recreate command buttons in the runtime. Below is a sample project.

Create a new Standard EXE project.
Add a textbox called text1.
Add a commandbutton call command1
Change the Index property of the commandbutton to 0
Add the following code to the form

Private Sub Command1_Click(Index As Integer)
Dim liCnt As Integer
  Select Case Index
    Case 0
      For liCnt = Command1.UBound + 1 To Command1.UBound + Val(Text1) - 1
        Load Command1(liCnt)
        Command1(liCnt).Visible = True
        Command1(liCnt).Top = Command1(liCnt - 1).Top + Command1(liCnt - 1).Height
      Next liCnt
  End Select
End Sub

Hope this helps.
merciAuthor Commented:
Thanks, That excatly what i wanted, Also Thanks "jjbyers" for your comments..
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.