Get Property value of class instance by passing string property name

M

mrussell

Does anyone know how to get the value of a property of an instance of
a class by passing the string as the name of the property?

I have seen it somewhere before e.g.
GetPropertyValueForClass(myClass,"PropertyName")

Any help would be really appreciated

Thanks

Mark
 
P

Peter T

Hi Mark,

Are you thinking of CallByName, eg

' code in normal module
Sub test()
Dim cls As Class1
Set cls = New Class1
CallByName cls, "PropA", VbLet, 123
MsgBox CallByName(cls, "PropA", VbGet)
End Sub

' code in Class1
Private mnID As Long

Public Property Let PropA(ID As Long)
mnID = ID
End Property

Public Property Get PropA() As Long
PropA = mnID
End Property


Regards,
Peter T
 
C

Chip Pearson

Use CallByName:

Dim Res As Variant
Dim PropName As String
Dim Obj As New Class1
' some code to set up Obj
PropName = "MyProperty"
Res = CallByName(Obj, PropName, VbGet)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top