Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Get Property value of class instance by passing string property name

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Get Property value of class instance by passing string property name

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


wrote in message
oups.com...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Get Property value of class instance by passing string property name

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)

wrote in message
oups.com...
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing several parameters to OnAction property. LABKHAND Excel Discussion (Misc queries) 1 April 24th 09 08:02 PM
How to cycle through each of property and its value of Class? Tetsuya Oguma Excel Worksheet Functions 1 March 3rd 06 10:36 AM
Property Let: assign return value of Double when passing String Tetsuya Oguma Excel Discussion (Misc queries) 1 March 3rd 06 08:01 AM
Cannot set HorizontalAlignment Property of the Range Class Alan Excel Programming 10 December 10th 04 12:57 AM
Using Property Let with a Type as member of a Class Ken Dahlberg Excel Programming 5 December 21st 03 05:57 AM


All times are GMT +1. The time now is 06:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"