Click here to Skip to main content
11,644,731 members (66,645 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB6 Runtime
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 15:07pm
Edited 25-Jun-12 15:21pm
Sergey Alexandrovich Kryukov at 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 at 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 at 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 at 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 at 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 at 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
0 OriginalGriff 680
1 494
2 Sergey Alexandrovich Kryukov 464
3 Afzaal Ahmad Zeeshan 404
4 CPallini 386
0 OriginalGriff 1,020
1 Sergey Alexandrovich Kryukov 673
2 DamithSL 656
3 Afzaal Ahmad Zeeshan 652
4 CPallini 555

Advertise | Privacy | Mobile
Web01 | 2.8.150731.1 | Last Updated 27 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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