Click here to Skip to main content
13,765,568 members
Rate this:
Please Sign up or sign in to vote.
See more:
Does anyone know how to create object (like textbox, command button, label, and so on) on runtime with VB6?
I means that when I clicked one button or do any action, then new textbox will appear.

In VB.Net look like this
Dim txt as New Textbox

But in VB6 don't know what's "New"..

Many Thanks

update : I intended to create new object from scratch, so we won't use any object that had been create then. <<--- If U know what I means, it's Control Array!
Posted 25-Jun-12 16:07pm
Updated 25-Jun-12 16:21pm
Sergey Alexandrovich Kryukov 25-Jun-12 21:11pm
Is there any single reason to deal with this garbage called "VB6" at all? And even ask questions about it?
Himachandra 29-Jun-12 3:43am
No sense at all.....
Y you are giving unreasonable suggestions....
If you know ans regarding ques...... then give it other wise
Sergey Alexandrovich Kryukov 29-Jun-12 18:00pm
Well, this is you who think this suggestion is unreasonable (even though it was just a question, suggestive, perhaps). I'm sure VB6 makes no sense at all. Do you see any single reason to use it? :-)
satrio_budidharmawan 25-Jun-12 21:14pm
I don't know why, but there're many student still VB6-ing on their Final Project, that's too shame..
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Create a Control dynamically at Run time. Without using a Control Array. That is the control is not present at Design time But will appear at Run Time.

option Explicit
Dim withevents Cmd1 as CommandButton
private Sub Form_Load()
set Cmd1 = Controls.Add("vb.commandbutton", "Cmd1")
Cmd1.Width = 2000
Cmd1.Top = me.Height / 2 - Cmd1.Height / 2 - 100
Cmd1.Left = me.Width / 2 - Cmd1.Width / 2 - 100
Cmd1.Caption = "Dynamic Button"
Cmd1.Visible = true
End Sub
private Sub Cmd1_click()
MsgBox "I have been Created Dynamically at Run-time", _
, "Dynamic Controls"
End Sub
satrio_budidharmawan 26-Jun-12 2:15am
how if I need to create a lot of textbox (say it 100 of textbox)?
Do I need to
Dim cmd1 to cmd100?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Why don't you create the Textbox and set it wherever you want and set it's visibility property to false, then based on whatever you want say another button click that you set it to visible. Just a thought!!!!
satrio_budidharmawan 2-Jul-12 21:16pm
Nope, you forget the terms "Dynamically"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.181114.1 | Last Updated 27 Jul 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100