Solved

Passing Controls to Active X Components

Posted on 2001-06-21
10
237 Views
Last Modified: 2013-11-25
Is it possible to pass a control, say List Box, to an Active X to populate?

e.g The Active X populates List1 with numbers 1 - 5, I want to call this several times in several apps but pass different listbox references to List1.

Cheers,
R
0
Comment
Question by:rallsaldo
  • 4
  • 4
  • 2
10 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6214479
Yes, it is possible...
Have you some specific problem with this?
You might note that the parameter type should be Control and not Listbox...

Public Sub FillListBox ( list as Control )
  dim l as ListBox
  set l = list

  l.AddItem "1"
  l.AddItem "2"
  ...

End Sub

CHeers
0
 
LVL 4

Author Comment

by:rallsaldo
ID: 6214609
Cheers a,

I have tried the control approach....

What exactly I am trying to do is have a private reference to mlstListBox in my class. I have a Let statement which allows me to set the value of mlstListBox to whatever Listbox name I choose, then a public sub which populates this mlstListBox.

Thus enabling me to have a dll which populates a listbox with a set of items regardless of what listbox I pass.

Currently it is falling over at the Let statement with the comment "Private object modules cannot be used in public object models as parameters or return types for public procedures, as public data members, or as fields of publuc user defined types"

Cheers,
R
0
 
LVL 15

Expert Comment

by:ameba
ID: 6214756
There are two ways to solve this.

' 1. Pass Listbox 'As Object' - this is Late bound call (slow)
' Class1 in ActiveX Dll
Option Explicit

Public Sub Populate(List As Object)
    List.Clear
    List.AddItem "Hello"
End Sub

' usage:
Private Sub Form_Click()
    Dim x As Project2.Class1
    Set x = New Class1
    x.Populate List1
End Sub



' 2. Early bound solution - add variable in Class1 declarations
' Class1 in ActiveX Dll
Option Explicit
Public List As ListBox

Public Sub Populate()
    If Not List Is Nothing Then
        List.Clear
        List.AddItem "Hello"
    End If
End Sub

' usage:
Private Sub Form_Click()
    Dim x As Project2.Class1
    Set x = New Class1
    Set x.List = List1
    x.Populate
End Sub
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6214759
First of all, to assign a Listbox, you need to use the SET statement...

Maybe you post your relevant code, so we can correct it?

---------Class code-------
private mlstListBox as ListBox

Public Property Set WorkListBox ( nv as Control )
  set mlstListBox = nv
End Property

Public Sub PopulateListBox()
  with mlstListBox
     .AddItem "1"
     .AddItem "2"
     ...
  end with
End Sub

--- Other code ----

with YourClass
  Set .WorkListBox = listbox1
  .Populate
  Set .WorkListBox = listbox2
  .Populate
end with



Cheers
0
 
LVL 4

Author Comment

by:rallsaldo
ID: 6214907
Cheers folks... I've pretty much tried this anyhow.

This is the code:

---Class Code---
Private mlstListBox As ListBox

Public Property Set MyListBox(vListBox As Control)
   
    Set mlstListBox = vListBox
       
End Property

This is were it is failing. If you paste it into a new Class you'll see what I mean when trying to compile.

This is probably blindingly obvious but got me stumped!!

Cheers,
R
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Accepted Solution

by:
ameba earned 100 total points
ID: 6214923
I tested both solutions I posted and they worked. I suggest 2nd solution.

' usage (code in a form with a listbox):
Private Sub Form_Click()
   Dim x As Project2.Class1
   Set x = New Class1
   Set x.List = List1
   x.Populate
End Sub
0
 
LVL 4

Author Comment

by:rallsaldo
ID: 6215242
Hi Ameba,

Yep this works fine ~ thanks ~ I've always declared variables as private in a class and then used the property let, property get to expose them to users. I take it this is different with controls?

Cheers,
R
0
 
LVL 15

Expert Comment

by:ameba
ID: 6215293
>I take it this is different with controls?

Well, if you want early binding, and if code is in a different project, yes, that is the syntax that is supported by VB.

Public X As ListBox
or:
Public WithEvents X As ListBox
0
 
LVL 15

Expert Comment

by:ameba
ID: 6217727
B?  What was wrong with my answer?  You got perfect expertize on how to do what you want with code samples (both code samples required creating program group)

Do not expect any further help from me!
0
 
LVL 4

Author Comment

by:rallsaldo
ID: 6218701
Ameba,

It was my first question asked and I was simply following the guidleines set out on the response page...

B: The Expert(s) provided an acceptable solution, or a link to an acceptable solution, that you were able to use, although you may have needed a bit more information to complete the task.

If you don't think that I awarded fairly then I apologise, I am grateful for your help, perhaps I should award A's to everyone... then everyones happy.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel - Save a copy of work book 13 82
Microsoft Access combo box help 2 37
Add and format columns in vb6 7 46
What .NET website keeps me current? 9 55
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now