Returning Properties Values
Is there a way to return the value for each of the property for an object?
Similar to this but on the same level as the Properties such as Connection and ConnectionString:
Code:
Dim adoProp As ADODB.Property
For Each adoProp In adoConn.Properties
Next
http://www.vbforums.com/showthread.p...ate+properties
Re: Returning Properties Values
I believe someone named Westconn1 or something posted code for this awhile back. I don't know if he used the TypeLibrary Information "TLBINF32.DLL" or something like that to do it. But if you can find his name you may be able to find the post, or maybe PM him. Hopefully I am remembering correct and it wasn't someone else that posted it. :)
Re: Returning Properties Values
Thank for the info DigiRev! I will look into WestConn's post.
I did find this:
http://www.vbforums.com/showthread.p...ate+properties
Re: Returning Properties Values
Hm, I don't think that is the one. That is back from 2001, and I'm still pretty sure it was westconn1 that posted it, and I don't remember it being too long ago but wasn't very recently either.
But does the code in that thread do what you want?
I would send him a PM and apologize for me in advance if he is indeed not the one that posted it. :)
Re: Returning Properties Values
I did a search with "TLBINF32.DLL" and "WestConn" (as well as "WestConn1") but nothing popped up.
I did do another search with "TLBINF32" only and only 5 posts popped up.
Re: Returning Properties Values
I had something about TypeLibs bookmarked, and it may be what you were thinking of:
http://www.vbforums.com/showthread.php?p=2977810
With some modifications, the code in post #2 should do the trick I think.
Re: Returning Properties Values
Hi Si_The_Great!:wave:
The code does not seem to return the value of the property but will test it out tonight when I get to my home computer with VB6.
Thank You
Re: Returning Properties Values
It won't work as-is, but should be fairly close.. I suspect that member will have several properties in addition to the name, including a value (and data type info, etc).
Re: Returning Properties Values
What you need to do is using CallByName with each Member Name
Re: Returning Properties Values
Searching from si's link, I also found this, not sure if you came across it or not:
http://www.vbforums.com/showthread.php?t=476509
Re: Returning Properties Values
I am going to test this out tonight and will let you all know the progress. Thanks and remember to check back to this thread.
Re: Returning Properties Values
OK, here it is, it's really easy when properties are string, numbers.. but things get more complicated when objects are returned, because you need to assign that to another Object, and sometimes arrays, collections or empty objects are returned and you need different code according to that, so manage returned values according to your objects, using a Form as parameter it works with this code, but it would also depend and what Controls are present in the Form. lMembers.ReturnType gives you the type of whatever is returning, it's a TliVarType, if you right click one of these, like VT_BSTR and click definition, you'll see the complete list. Add a ListBox to your Form.
Code:
Private Sub GetMembers(pList As ListBox, pObject As Object)
Dim TLI As TLIApplication
Dim lInterface As InterfaceInfo
Dim lMember As MemberInfo
Dim lObjRet As Object
Dim lStrRet As String
Dim lRetType As TliVarType
Set TLI = New TLIApplication
Set lInterface = TLI.InterfaceInfoFromObject(pObject)
For Each lMember In lInterface.Members
If lMember.InvokeKind = INVOKE_PROPERTYGET Then
lRetType = lMember.ReturnType
Select Case lRetType
Case VT_DISPATCH
Set lObjRet = CallByName(pObject, lMember.Name, VbGet, 0)
pList.AddItem lMember.Name & " = " & lObjRet
Case VT_EMPTY
'You should do nothing here, but doing the following you will see the same than the
'Prop window shows in VB, sometimes it's a a number, like in props Picture, Image, Font, Icon...
Set lObjRet = CallByName(pObject, lMember.Name, VbGet)
If Not (lObjRet Is Nothing) Then pList.AddItem lMember.Name & " = " & lObjRet
Case Else '(VT_BSTR = String, VT_BOOL = Boolean,VT_DATE, VT_DECIMAL, VT_VARIANT..etc)
lStrRet = CallByName(pObject, lMember.Name, VbGet)
pList.AddItem lMember.Name & " = " & lStrRet
End Select
End If
Next
Set pObject = Nothing
Set lInterface = Nothing
Set TLI = Nothing
End Sub
Private Sub Form_Load()
GetMembers List1, Me
End Sub
EDIT: I forgot, add a reference to "TLBINF32.DLL" it's in C:\Windows\System32
Re: Returning Properties Values
Thank You so much JCIS. I will validate tonight.
Re: Returning Properties Values
JCIS, that is pretty much what i am looking for. Too bad it does not do recursive to look for such as "Properties" and so on. I will look into this but thank you for getting me started with the code that you supplied.
I also want to say thank you to everyone else too. Will make my life much easier to test properties out.:thumb: :afrog: