Newbie Q: Creating objects at runtime 
Author Message
 Newbie Q: Creating objects at runtime

Hi folks,

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?

Thanks,
Tim.
--

Remember that you're unique - just like everyone else.

All opinions are my own and are not necessarily those of my employer.



Sun, 02 Dec 2001 03:00:00 GMT  
 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.



Sun, 02 Dec 2001 03:00:00 GMT  
 Newbie Q: Creating objects at runtime
Tim

There are two ways:

In VB6 you can use the Add method of the Controls collection of a Form.

In previous versions you have to put a control like the one you will want to
create on the form and set its Index property to 0. At run-time, perform
something like:

Load myControl(1)
myControl.Visible = True

--
Regards
{*filter*}

Remove '!no!spam!' to reply by e-mail but reply to newsgroup as well.


Quote:
> Hi folks,

> 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?

> Thanks,
> Tim.
> --

> Remember that you're unique - just like everyone else.

> All opinions are my own and are not necessarily those of my employer.



Sun, 02 Dec 2001 03:00:00 GMT  
 Newbie Q: Creating objects at runtime
To create new controls, you can use the Load() statement as prior
respondents suggested.

Starting with VB6, though, you have the option of creating controls somewhat
out of thin air.  Please look up Dynamic Control Creation in the VB6 docs,
What's New section.



Sun, 02 Dec 2001 03:00:00 GMT  
 Newbie Q: Creating objects at runtime
Thanks very much for your help, folks.  I've got it to work using both
the indexing method and the new VB6 controls collection method.  I'm
having trouble triggering events with the latter, but I'll do some
more research before I hassle you good people further.

Cheers,
Tim.

--

Remember that you're unique - just like everyone else.

All opinions are my own and are not necessarily those of my employer.



Mon, 03 Dec 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Newbie Qs: Optimizing Stylesheet with Fields

2. Activex Component Can’t Create Object - Runtime Error 429

3. Runtime error '429', ActiveX can't create object

4. Creating objects at runtime

5. Creating objects in runtime using the mouse??

6. Creating labels or other objects at runtime

7. Create Object at Runtime Help

8. Create Active X Object at runtime

9. Runtime error 429 when creating Word object

10. creating objects at runtime in VB 5.0

11. Creating Objects at Runtime

12. HELP : runtime error 429 ActiveX can't create object

 

 
Powered by phpBB® Forum Software