
Newbie Q: Creating objects at runtime
Quote:
>I'm assuming that there is a way for VB6 to create objects such as a
>textbox or command button at runtime, but can't figure out how to do
>it. I came across an example that creates another form every time you
>click a button, but had no success converting it to do the same for
>other objects. Can someone please enlighten me?
You need to use control arrays.
Assuming you have at least one control on your form, with index not
Null, e.g. a textbox text1(0). Use
Load text1(i)
with i a positive number, and text1(i) not in use yet. You'll create a
copy of text1(0), same properties as the original, but invisible.
There's no way to create an entirely different control at runtime, as
you already must have compiled the event code for this control. So: the
event code is common to all controls in this control array, but you have
an extra parameter, index, to see exactly which one you're currently
dealing with.
You could use it's Tag property, for example, to differentiate between
subtypes of your control.
HTH,
Bart.