473,395 Members | 1,774 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,395 software developers and data experts.

best way to randomly access my class members

I have a class that has responses to a survey. Some questions have text
answers, and some have enum answers (integer type). All have ResponseIDs.
If I'm passed data in random order of responseIDs, is there a way to access
the right member within the class?

Public Structure TextResponse
Public RespID As Integer
Public Text As String
End Structure
Public Class AssessmentCls
Private _Q001 As Integer = Q001resp.No
Public Enum Q001resp As Integer
Yes = 1
No = 5
End Enum

Public Property Q001() As Q001resp
Get
Return _Q001
End Get
Set(ByVal Value As Q001resp)
_Q001 = Value
End Set
End Property

Public Enum Q005resp As Integer
FreeFormText = 6
End Enum
Private _Q005 As TextResponse

Public Property Q005() As String
Get
Return _Q005.Text
End Get
Set(ByVal Value As String)
_Q005.Text = Value
_Q005.RespID = Q005resp.FreeFormText
End Set
End Property

Lets say that the first responseID I get is 6. That means that the data is
for _Q005.
Is there some way I can set up a hashtable or something like that for the
class, so that I can get directly to _Q005 rather than having to search
through the class to find a match on ResponseID of 6?

Jun 27 '06 #1
2 1046
Can I use a Hashtable like this? As I see it, there is no late binding, so
this doesn't work::

Public hTable As New Hashtable
Public Sub New()
hTable.Add(Q001resp.No, Q001)
hTable.Add(Q001resp.Yes, Q001)
hTable.Add(Q005resp.FreeFormText, Q005)
hTable.Add(Q006resp.FreeFormText, Q006)
hTable.Add(Q007resp.FreeFormText, Q007)
hTable.Add(Q008resp.FreeFormText, Q008)
hTable.Add(Q009resp.FreeFormText, Q009)
hTable.Add(Q010resp.Alone, Q010)
hTable.Add(Q010resp.Other, Q010)
hTable.Add(Q010resp.wChildren, Q010)
hTable.Add(Q010resp.wFriends, Q010)
hTable.Add(Q010resp.wFriendsAndChildren, Q010)
hTable.Add(Q010resp.wRelatives, Q010)
hTable.Add(Q010resp.wRelativesAndChildren, Q010)
hTable.Add(Q010resp.wSpouse, Q010)
hTable.Add(Q010resp.wSpouseAndChildren, Q010)
hTable.Add(Q011resp.FreeFormText, Q011)
hTable.Add(Q012resp.FreeFormText, Q012)
hTable.Add(Q013resp.No, Q013)
hTable.Add(Q013resp.Yes, Q013)
hTable.Add(Q014resp.No, Q014)
hTable.Add(Q014resp.Yes, Q014)
hTable.Add(Q015resp.FreeFormText, Q015)
hTable.Add(Q016resp.No, Q016)
hTable.Add(Q016resp.Yes, Q016)
hTable.Add(Q017resp.FreeFormText, Q017)
hTable.Add(Q018resp.No, Q018)
hTable.Add(Q018resp.Yes, Q018)
End Sub

If there was a way to pass a reference to Q018 for example, then it would
work. using AddressOf wont work, because Hashtable takes Objects, not
delegate types.

"HockeyFan" wrote:
I have a class that has responses to a survey. Some questions have text
answers, and some have enum answers (integer type). All have ResponseIDs.
If I'm passed data in random order of responseIDs, is there a way to access
the right member within the class?

Public Structure TextResponse
Public RespID As Integer
Public Text As String
End Structure
Public Class AssessmentCls
Private _Q001 As Integer = Q001resp.No
Public Enum Q001resp As Integer
Yes = 1
No = 5
End Enum

Public Property Q001() As Q001resp
Get
Return _Q001
End Get
Set(ByVal Value As Q001resp)
_Q001 = Value
End Set
End Property

Public Enum Q005resp As Integer
FreeFormText = 6
End Enum
Private _Q005 As TextResponse

Public Property Q005() As String
Get
Return _Q005.Text
End Get
Set(ByVal Value As String)
_Q005.Text = Value
_Q005.RespID = Q005resp.FreeFormText
End Set
End Property

Lets say that the first responseID I get is 6. That means that the data is
for _Q005.
Is there some way I can set up a hashtable or something like that for the
class, so that I can get directly to _Q005 rather than having to search
through the class to find a match on ResponseID of 6?

Jun 27 '06 #2
I continued this question in a thread about Delegates, thinking that I could
set up a delegate to accomplish this. The thing is, Delegates are definied
for a particular datatype, and in my case, some of the properties are Integer
and some are String.

"HockeyFan" wrote:
Can I use a Hashtable like this? As I see it, there is no late binding, so
this doesn't work::

Public hTable As New Hashtable
Public Sub New()
hTable.Add(Q001resp.No, Q001)
hTable.Add(Q001resp.Yes, Q001)
hTable.Add(Q005resp.FreeFormText, Q005)
hTable.Add(Q006resp.FreeFormText, Q006)
hTable.Add(Q007resp.FreeFormText, Q007)
hTable.Add(Q008resp.FreeFormText, Q008)
hTable.Add(Q009resp.FreeFormText, Q009)
hTable.Add(Q010resp.Alone, Q010)
hTable.Add(Q010resp.Other, Q010)
hTable.Add(Q010resp.wChildren, Q010)
hTable.Add(Q010resp.wFriends, Q010)
hTable.Add(Q010resp.wFriendsAndChildren, Q010)
hTable.Add(Q010resp.wRelatives, Q010)
hTable.Add(Q010resp.wRelativesAndChildren, Q010)
hTable.Add(Q010resp.wSpouse, Q010)
hTable.Add(Q010resp.wSpouseAndChildren, Q010)
hTable.Add(Q011resp.FreeFormText, Q011)
hTable.Add(Q012resp.FreeFormText, Q012)
hTable.Add(Q013resp.No, Q013)
hTable.Add(Q013resp.Yes, Q013)
hTable.Add(Q014resp.No, Q014)
hTable.Add(Q014resp.Yes, Q014)
hTable.Add(Q015resp.FreeFormText, Q015)
hTable.Add(Q016resp.No, Q016)
hTable.Add(Q016resp.Yes, Q016)
hTable.Add(Q017resp.FreeFormText, Q017)
hTable.Add(Q018resp.No, Q018)
hTable.Add(Q018resp.Yes, Q018)
End Sub

If there was a way to pass a reference to Q018 for example, then it would
work. using AddressOf wont work, because Hashtable takes Objects, not
delegate types.

"HockeyFan" wrote:
I have a class that has responses to a survey. Some questions have text
answers, and some have enum answers (integer type). All have ResponseIDs.
If I'm passed data in random order of responseIDs, is there a way to access
the right member within the class?

Public Structure TextResponse
Public RespID As Integer
Public Text As String
End Structure
Public Class AssessmentCls
Private _Q001 As Integer = Q001resp.No
Public Enum Q001resp As Integer
Yes = 1
No = 5
End Enum

Public Property Q001() As Q001resp
Get
Return _Q001
End Get
Set(ByVal Value As Q001resp)
_Q001 = Value
End Set
End Property

Public Enum Q005resp As Integer
FreeFormText = 6
End Enum
Private _Q005 As TextResponse

Public Property Q005() As String
Get
Return _Q005.Text
End Get
Set(ByVal Value As String)
_Q005.Text = Value
_Q005.RespID = Q005resp.FreeFormText
End Set
End Property

Lets say that the first responseID I get is 6. That means that the data is
for _Q005.
Is there some way I can set up a hashtable or something like that for the
class, so that I can get directly to _Q005 rather than having to search
through the class to find a match on ResponseID of 6?

Jun 27 '06 #3

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

Similar topics

7
by: Wolfgang Jeltsch | last post by:
Hello, I want to write a list class with an iterator class as an inner class. The iterator class must have access to certain private members of the list class in order to do its job. Here is a...
8
by: CoolPint | last post by:
I read in books that nested class cannot access private members of nesting class and vice versa unless they are made friends. Somehow, my compiler is letting my nested class member functions access...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
6
by: Droopy | last post by:
Hi, I want to add unit tests in my application using NUnit. At first, I thought to add unit tests in the class that is tested, enclosed in a conditional attribute to remove these unit tests from...
10
by: Abelardo Vacca | last post by:
Hi, The title sums up the question pretty much. I would like to access all private members of a class including the private members of its base classes.( I already have the ReflectionPermission )...
5
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all...
1
by: D Witherspoon | last post by:
Coming up with a scenario here. For example there is the standard .NET MailMessage class. I am creating a project (let's call it CommonBase) that has the following 2 classes ...
41
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
15
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I met with a strange issue that derived class function can not access base class's protected member. Do you know why? Here is the error message and code. error C2248:...
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:
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.