473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Refer to class-properties (A97)

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
Nov 13 '05 #1
4 1752
rkc
Arno R wrote:
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' ?


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"
Nov 13 '05 #2

"rkc" <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in message
news:zu*******************@twister.nyroc.rr.com...
Arno R wrote:
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' ?


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"

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.
Nov 13 '05 #3
rkc
Brian Wilson wrote:
could I persuade you to have a look at my
TaggedValues question? This should appear a few posts down from this one.


Any thing for the creative genius behind the Beach Boys.
Nov 13 '05 #4
"rkc" <rk*@rochester.yabba.dabba.do.rr.bomb> schreef in bericht news:zu*******************@twister.nyroc.rr.com...
Arno R wrote:
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' ?


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"


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
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ivo | last post by:
How do I make the magic 'this' variable refer to an object of my choice, in a string of code which is to be eval'ed? Say, I have an object, an array with four elements: var myobject = ; and a...
5
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
2
by: john | last post by:
OK, The problem isn't with Addhandler, it's with my understanding of Shared... I add a handler like this: AddHandler ct.ColumnChanged, New _ DataColumnChangeEventHandler(AddressOf...
4
by: SamSpade | last post by:
If I have a class that inherits from, say RichTextBox and in the derived class I refer to Handle, does it refer to the RichTextBox class or the derived class? I'm wondering if the derived class...
0
by: Larry Lard | last post by:
This came out of a thread explaining to "BK" about error BC42025 ("Access of shared member through an instance; qualifying expression will not be evaluated"); Frans Clasener then came up with...
1
by: shivapadma | last post by:
1..In java we can refer superclass constructor by super()keyword,but Where as in c++ how can we refer to that???. In java the following code is used for referring superclass...
1
by: mrstephengross | last post by:
I've got a Base class with an attribute "foo" (of type Foo), and a Derived class (derived from Base). In Derived's constructor, I try to refer to Base.foo, but python complains: AttributeError:...
8
by: Andy B | last post by:
Is there a way to refer to things in Session object without calling Session itself?
5
by: Web Search Store | last post by:
Hello, I made a web page using visual studio. I also made a public class in the app_code folder called 'allvars' In the main web page durning the page startup, I can refer to public shared...
2
by: Rick | last post by:
First of all, is there a group more specific to WPF? I have a WPF form and I want to bind to a local member variable from the xaml. the code behind is like this: Partial Public Class...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.