Connecting Tech Pros Worldwide Forums | Help | Site Map

Refer to class-properties (A97)

Arno R
Guest
 
Posts: n/a
#1: Nov 13 '05
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' ?

At the moment I am sure I am doing this wrong ... (the code is beginning to taste like spaghetti ...)

Arno R



rkc
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Refer to class-properties (A97)


Arno R wrote:[color=blue]
> 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"


Brian Wilson
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Refer to class-properties (A97)



"rkc" <rkc@rochester.yabba.dabba.do.rr.bomb> wrote in message
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
I've just been Googling on this subject and your name keeps cropping up. If
I provided a small amount of flattery (such as these are the most
informative posts I've seen) could I persuade you to have a look at my
TaggedValues question? This should appear a few posts down from this one.


rkc
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Refer to class-properties (A97)


Brian Wilson wrote:
[color=blue]
> could I persuade you to have a look at my
> TaggedValues question? This should appear a few posts down from this one.[/color]

Any thing for the creative genius behind the Beach Boys.
Arno R
Guest
 
Posts: n/a
#5: Nov 13 '05

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
Closed Thread


Similar Microsoft Access / VBA bytes