• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

Does anyone know how to list Public Procedures at runtime?

Hi,
I am building an ActiveX control that allows the user to specify a Public Function or Sub Routine that can be called when the control's Calculate method is called.

The functions/sub routines are stored in a seperate class and the CallByName method is used
to call them.

I would ideally like to list all of the available Public procedures in a combo box on a Property Page so it is only possible to select a valid procedure name. I have no idea how to do this in Visual Basic 6.

Can anyone help!?
0
joboy
Asked:
joboy
1 Solution
 
bob_onlineCommented:
VB isn't going to automatically do this for you.  You're going to have hard code names to load into the combo box.  I like the idea, though
0
 
JohnChapinCommented:
Shouldn't the list of names be a property of the class itself?  Just to keep the object orientation.
0
 
joboyAuthor Commented:
I had wondered whether or not I should add a dynamic property that would expose a collection of Procedure Names. Where the procedure names are hardcoded into the class.

I'm not too keen on doing it this way because the class contains around 40 procedures.  Each procedure in the class carries out a specific calculation (the control I'm building is kind of like Excel but designed for a specific task). Not only this it is highly likely that people will decide that calculations need adding/changing.  This means the hardcoded procedure names must be kept up to date (a pain!).

Anyway... I'm presuming that as the Object Browser can list procedures etc., there must be a way of doing it. Maybe an API call or something!?

Cheers for the help so far..
Joseph
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
HermeticCommented:
Possibly, the solution lies in the CodeModule object's
property Members (a collection of Member objects).
0
 
hazgodCommented:
why not store the names in an array, which can be added to. then populate the listbox with the names from the array
0
 
joboyAuthor Commented:
Cheers for the help so far...
I have found a possible solution to the problem... I've added a reference to the TLBInf32 dll to my project and using this I seem to able to obtain the info I require. Here's the sample code below...

Sub Test()
    Dim t As New TLI.TLIApplication
    Dim typInfo As TLI.TypeInfo
    Dim memFo As TLI.MemberInfo
    Dim interface As TLI.InterfaceInfo
   
    'MsgCentre1 is just a ActiveX usercontrol I created
    'myself and added as a component to my project, so
    'I had something to reference
    Set typInfo = t.ClassInfoFromObject(MsgCentre1)
    For Each interface In typInfo.Interfaces
        For Each memFo In interface.Members
            If memFo.InvokeKind = INVOKE_FUNC Then
                Debug.Print memFo.Name
            End If
        Next
    Next
   
    Set interface = nothing
    Set typInfo = Nothing
    Set memFo = Nothing
    Set t = Nothing
End Sub

The only problem I'm having with the code now is that it seems to be listing additional functions (presumably created internally by VB) alongside my functions...

Anyone know how to correct this problem?

P.s. The CodeModule solution I pretty sure is specific to the VBE object (i.e. Microsoft Office VBA) and works on non-compiled visual basic.
0
 
CleanupPingCommented:
joboy:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now