| re: Refer to class-properties (A97)
"rkc" <rkc@rochester.yabba.dabba.do.rr.bomb> schreef in bericht news:zunVe.56296$PM3.54654@twister.nyroc.rr.com...[color=blue]
> Arno R wrote:[color=green]
>> Hi all,
>>
>> I have lots of properties in a class. (clsTest)
>>
>> Properties are created like (simplified ...)
>> Public ItemA as string
>> Public ItemB as string
>> Public ItemC as string
>> ...
>> Public CountA as integer
>> Public CountB as integer
>> Public CountC as integer (I did not use Property Let/Get for any of these props)
>> ...
>>
>> I need to refer to the values of these properties like:
>>
>> Sub TestValues(input)
>> Dim oTest as clsTest
>> Set oTest=New clsTest
>> Dim strItemvalue as string
>> Dim intCountValue as Integer
>> strItemValue = oTest.Item & input <== wrong
>> intCountValue=oTest.Count & input <== wrong
>> End sub
>>
>> I tried oTest("Count" & input) <== wrong also.
>> I can't figure this out at the moment.
>> Is there a way to do this without 'Select case input' ?[/color]
>
> Your confusing properties of an object with a properties collection.
> There is no automagically created properties collection when you
> define your own objects using a Class module.
>
> While you might be able to do what you want using Eval() it would
> still be wrong headed.
>
> You need to define a VBA.Collection object as a member of your Class
> and store your "string properties" using key values of ItemA, ItemB,
> etc. The you can retrieve them in the way you're trying to now.
>
> dim properties as new vba.collection
> properties.add "Turkey Breast", "ItemA"
> properties.add "Meat Loaf", "ItemB"
>
> input = "A"
> strItemValue = properties("Item" & input) '----> "Turkey Breast"[/color]
Hi rkc,
Thanks for clearing my dusty brain on this !
I will go for the collection object, but I would also like to know how to use Eval() in this case
strItemValue = Eval("oTest.Item" & input) is not working ...
Arno R |