Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

dynamically accessing properties of a object

Posted on 2004-10-28
2
Medium Priority
?
161 Views
Last Modified: 2010-05-02
Hi,

I want the following:

function here(a as object,id as string) as object
  here = a.id
end function

id does not have to be a string, but it needs to be generic.  That is I don't want to have to check types for id.
0
Comment
Question by:rmundkowsky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 2000 total points
ID: 12439507
You can use the CallByName function...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vafctcallbynamefunction.asp

e.g.

property = CallByName(a, "id", vbGet)
0
 

Author Comment

by:rmundkowsky
ID: 12439545
Right now, thanks!

Public Function find(thingToSearch As Collection, keyToFind As Variant, attributeToMatch As String) As Collection
    Dim temp As Object
    Dim tempCollection As Collection
    Dim varB

    Set tempCollection = New Collection
   
    For i = 1 To thingToSearch.Count
        Set temp = thingToSearch.Item(i)
       
       


        varB = CallByName(temp, attributeToMatch, VbGet)
        'if typeof temp is VBA.
        'changing attributeToMatch from a string is hard, but I think it can be done
        '  also we need to have multiple if then's for
        If StrComp(TypeName(varB), "String") = 0 Then
            If StrComp(varB, keyToFind) = 0 Then
                    Set find = tempCollection
                    tempCollection.Add temp
            End If
        Else
            If keyToFind = varB Then
                Set find = tempCollection
                tempCollection.Add temp
            End If
        End If
    Next

    If tempCollection.Count = 0 Then
        Set find = Nothing
    End If

End Function


0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

604 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