best way to randomly access my class members

G

Guest

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?
 
G

Guest

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top