Create Object at Runtime Help 
Author Message
 Create Object at Runtime Help

I'm wanting to add objects into a control array.  The Image object to
be exact.  Let's say I had "Image1(0)" I was working with.  And when I
clicked a button, POOF! Suddenly I have an additional Image object.
"Image1(1)" to be exact.  Now...  How do I accomplish this?

Anyone have any code I can see that explains this?

And...how do I "delete" the object at runtime if I'm done with it?

Paul



Wed, 02 Jan 2002 03:00:00 GMT  
 Create Object at Runtime Help
Whoa, I found my answer even before I left the newsgroup!  I use the

load (object) command after making an initial object(0) on the form.

Pretty cool!

BUT...

How do I detect if an object exists before assigning the new object an
array value?

Paul


Quote:

>I'm wanting to add objects into a control array.  The Image object to
>be exact.  Let's say I had "Image1(0)" I was working with.  And when I
>clicked a button, POOF! Suddenly I have an additional Image object.
>"Image1(1)" to be exact.  Now...  How do I accomplish this?

>Anyone have any code I can see that explains this?

>And...how do I "delete" the object at runtime if I'm done with it?

>Paul



Wed, 02 Jan 2002 03:00:00 GMT  
 Create Object at Runtime Help
The program needs to track the last index inserted.


Quote:

> Whoa, I found my answer even before I left the newsgroup!  I use the

> load (object) command after making an initial object(0) on the form.

> Pretty cool!

> BUT...

> How do I detect if an object exists before assigning the new object an
> array value?

> Paul



> >I'm wanting to add objects into a control array.  The Image object to
> >be exact.  Let's say I had "Image1(0)" I was working with.  And when I
> >clicked a button, POOF! Suddenly I have an additional Image object.
> >"Image1(1)" to be exact.  Now...  How do I accomplish this?

> >Anyone have any code I can see that explains this?

> >And...how do I "delete" the object at runtime if I'm done with it?

> >Paul



Wed, 02 Jan 2002 03:00:00 GMT  
 Create Object at Runtime Help
Let's say I created six new image objects at runtime (control array).
Now...for some reason, I decide I don't need the third one.  (IE:
Image1(3) is unloaded.)

Later on in the program, I decide I want to add another control to the
array.  I'm wanting to see what the next available control array
number should be.  So I start by checking if Image1(1) exists.  If so,
then keep going until I find one that doesn't exist.

How is this done?



Thu, 03 Jan 2002 03:00:00 GMT  
 Create Object at Runtime Help
Firstly, place an imagebox on your form and set the picture for it.  Then
set the 'Index' property of the imageBox control to 0.
This will enable you to create the 'base' of the array.  Once you've done
that the following code will create the extra elements of the array for
you.  Be sure to always unload the array element once you've finished with
it.

You can set the properties for each element of the array seperately from
the original.

I've offset the created images so that they're not placed on the top of
the original.

I hope this helps ...

Option Explicit
    Dim i As Integer
    Dim NumOfImages As Integer

Private Sub cmdLoadArray_Click()
    NumOfImages = 3
    For i = 1 To NumOfImages
        Load Image1(i)
        Image1(i).Left = Image1(i - 1).Left + Image1(i - 1).Width
        Image1(i).Visible = True
    Next i
End Sub

Private Sub cmdUnloadArray_Click()
    For i = 1 To NumOfImages
        Unload Image1(i)
    Next i
End Sub


Quote:
> I'm wanting to add objects into a control array.  The Image object to
> be exact.  Let's say I had "Image1(0)" I was working with.  And when I
> clicked a button, POOF! Suddenly I have an additional Image object.
> "Image1(1)" to be exact.  Now...  How do I accomplish this?

> Anyone have any code I can see that explains this?

> And...how do I "delete" the object at runtime if I'm done with it?

> Paul



Thu, 03 Jan 2002 03:00:00 GMT  
 Create Object at Runtime Help
I use

Static IsDeleted() As Boolean
Dim i As Integer

For i = 0 To UBound(IsDeleted, 1)
    If IsDeleted(i) Then
        Do: Code
        Exit For
    End If
Next



Quote:
>Let's say I created six new image objects at runtime (control array).
>Now...for some reason, I decide I don't need the third one.  (IE:
>Image1(3) is unloaded.)

>Later on in the program, I decide I want to add another control to the
>array.  I'm wanting to see what the next available control array
>number should be.  So I start by checking if Image1(1) exists.  If so,
>then keep going until I find one that doesn't exist.

>How is this done?



Thu, 03 Jan 2002 03:00:00 GMT  
 Create Object at Runtime Help
Paul and Cindy,

If you want to re-use 'holes' left in the array by elements you've unloaded,
try something like:

Dim iBuf as Integer

On error resume next
With Image1
    For iBuf =  0 To .UBound - 1 ' there's obviously an element at .Index =
.UBound
        .Item(iBuf)
        if Err Then Exit For    ' element missing
    Next
    If Err Then
        Err.Clear
        On Error Goto 0
    Else
        iBuf = iBuf + 2 ' 1 past .UBound
    End If

    Load Image1(iBuf)
End With

Alternatively, if you don't mind leaving 'holes' in the array, try:

Load Image1(Image1.Ubound + 1)

--A



Fri, 04 Jan 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

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

2. Help: Creating Objects/Controls at runtime

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

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

5. Creating objects at runtime

6. Creating objects in runtime using the mouse??

7. Creating labels or other objects at runtime

8. Newbie Q: Creating objects at runtime

9. Create Active X Object at runtime

10. Runtime error 429 when creating Word object

11. creating objects at runtime in VB 5.0

12. Creating Objects at Runtime

 

 
Powered by phpBB® Forum Software