Results 1 to 3 of 3

Thread: [Resolved] Multiple instances of ActiveX at runtime?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Question [Resolved] Multiple instances of ActiveX at runtime?

    I'd swear I've seen this done, but can't remember how.

    I'd like to create an array of an activex component at runtime so that I can access multiple instances of it.

    Something like this pseudo-code:
    Code:
    Dim AXarray() as myActiveX
    
    Private Sub Form_Load()
        ReDim AXarray(2)
    
        AXarray(0).load "myfile"
    
        AXarray(1).load "yourfile"
    
        AXarray(2).load "ourfile"
    End Sub

    Can someone please help?

    Thanks.
    Last edited by wayneh; Oct 20th, 2004 at 06:31 PM.

  2. #2
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    Try using a collection.
    VB Code:
    1. Option Explicit
    2. '
    3. Private m_colControls As Collection
    4. '
    5.  
    6. Private Sub cmdCreate_Click()
    7.     Dim myControl As Collection
    8.     Dim i
    9.     '
    10.     Set m_colControls = New Collection
    11.     '
    12.     For i = 1 To 10
    13.         Set myControl = New Collection
    14.         myControl.Add CStr(i)
    15.         m_colControls.Add myControl
    16.         Set myControl = Nothing
    17.     Next
    18.     '
    19. End Sub
    20.  
    21. Private Sub cmdDisplay_Click()
    22.     Dim Control As Collection
    23.     '
    24.     For Each Control In m_colControls
    25.         Me.lstContainer.AddItem Control.Item(1)
    26.     Next
    27.     '
    28. End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406
    I found this solution on another Forum - works perfectly!

    Place one instance of the OCX on your form and give it an Index of 0. This creates a control array. During run-time you can load new instances of the control by using the Load keyword. Example follows:


    'Loading new instances of a control at run-time
    Dim i As Long

    'Get the next index to load
    i = TheOCX.UBound + 1

    'Load a new instance of the OCX control
    Load TheOCX(i)

    TheOCX(i).Visible = True
    TheOCX(i).Text = "TheOCX " & CStr(i)

    'and so on...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width