But if I have:
| list.Add("parmA1", "parmA2", "parmA3")
| list.Add("parmB1", "parmB2", "parmB3", "parmB4")
list.Add("parmC1")
The object returns:
| parmA1:
| item 0: parmA2
| item 1: parmA3
| parmB1:
| item 0: parmB2
| item 1: parmB3
| item 2: parmB4
Notice there is no output for parmC1, as parmC1 has no values, so there is
nothing to return. parmC1 is NOT placed into the collection.
Is no output what you would expect for parmC1? If not, what is the expected
output?
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
| OK. I tried your class with these args
|
|
| list.Add("parmA1", "parmA2", "parmA3")
| list.Add("parmB1", "parmB2", "parmB3", "parmB4")
|
| The object returns
|
| parmA1:
| item 0: parmA2
| item 1: parmA3
| parmB1:
| item 0: parmB2
| item 1: parmB3
| item 2: parmB4
|
| I don't see any problems.
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Doh!
| > | Public Overloads Sub Add(ByVal key As String, ByVal ParamArray
| > | values() As String)
| > | For Each value As String In values
| > | Add(key, value)
| > | Next
| > | End Sub
| > The above code assumes that not passing any values is NOT a problem.
which
| > may or may not be a valid assumption.
| >
| > Is:
| >
| > list.Add("parmA1")
| >
| > Valid?
| >
| >
| >
| > --
| > Hope this helps
| > Jay [MVP - Outlook]
| > ..NET Application Architect, Enthusiast, & Evangelist
| > T.S. Bradley -
http://www.tsbradley.net
| >
| >
| > message | > || Thanks for your suggestion of the NameValueCollection. May I ask if
you
| > || could share an example how it is used?
| > |
| > | Dim list As New
System.Collections.Specialized.NameValueCollection
| > | list.Add("parmA1", "parmA2")
| > | list.Add("parmA1", "parmA3")
| > | list.Add("parmB1", "parmB2")
| > | list.Add("parmB1", "parmB3")
| > |
| > | Dim a1 As String
| > | Dim b1 As String
| > | a1 = list.Item("parmA1")
| > | b1 = list.Item("parmB1")
| > |
| > | Dim a1s() As String = list.Item("parmA1").Split(","c)
| > | Dim b1s() As String = list.Item("parmB1").Split(","c)
| > |
| > | If you like you could encapsulate some of the logic into a custom
version
| > of
| > | NameValueCollection that supported adding a list of values for a key &
| > | returning one value for a key, something like:
| > |
| > | Public Class someCollectionObj
| > | Inherits System.Collections.Specialized.NameValueCollection
| > |
| > | Public Overloads Sub Add(ByVal key As String, ByVal ParamArray
| > | values() As String)
| > | For Each value As String In values
| > | Add(key, value)
| > | Next
| > | End Sub
| > |
| > | Default Public Overloads ReadOnly Property Item(ByVal key As
| > String,
| > | ByVal index As Integer) As String
| > | Get
| > | Dim values() As String = Item(key).Split(","c)
| > | Return values(index)
| > | End Get
| > | End Property
| > |
| > | Public ReadOnly Property ItemCount(ByVal key As String) As
Integer
| > | Get
| > | Return Item(key).Split(","c).Length
| > | End Get
| > | End Property
| > |
| > | End Class
| > |
| > | Then you could use the above, something like:
| > |
| > | Dim list As New someCollectionObj
| > | list.Add("parmA1", "parmA2", "parmA3")
| > | list.Add("parmB1", "parmB2", "parmB3", "parmB4")
| > |
| > | For Each key As String In list.Keys
| > | Debug.WriteLine(Nothing, key)
| > | Debug.Indent()
| > | For index As Integer = 0 To list.ItemCount(key) - 1
| > | Debug.WriteLine(list.Item(key, index), "item " & index)
| > | Next
| > | Debug.Unindent()
| > | Next
| > |
| > | I would consider adding an indexers like:
| > |
| > | Default Public Overloads ReadOnly Property Item(ByVal key As
| > String)
| > | As String()
| > | Get
| > | Return MyBase.Item(key).Split(","c)
| > | End Get
| > | End Property
| > |
| > | Default Public Overloads ReadOnly Property Item(ByVal index As
| > | Integer) As String()
| > | Get
| > | Return MyBase.Item(index).Split(","c)
| > | End Get
| > | End Property
| > |
| > | Which return an array of strings for a key/index rather then the comma
| > | delimited string.
| > |
| > | I might also consider an indexer something like:
| > |
| > | Default Public Overloads ReadOnly Property Item(ByVal indexKey
As
| > | Integer, ByVal indexValue As Integer) As String
| > | Get
| > | Dim values() As String =
MyBase.Item(indexKey).Split(","c)
| > | Return values(indexValue)
| > | End Get
| > | End Property
| > |
| > | If I needed to index that way...
| > |
| > | --
| > | Hope this helps
| > | Jay [MVP - Outlook]
| > | .NET Application Architect, Enthusiast, & Evangelist
| > | T.S. Bradley -
http://www.tsbradley.net
| > |
| > |
| > | | > || Thanks for your suggestion of the NameValueCollection. May I ask if
you
| > || could share an example how it is used?
| > ||
| > || As for keys, the first element in each row is unique so that could be
a
| > | key.
| > || Else, I was just going to loop through the collection. But I tried
| > | writing
| > || a class with the 3 properties of the stuff I need to store. But I
can't
| > || retrieve the values. The class effort is my 2nd post in this thread.
| > | Would
| > || you have any suggestions what I could do to the class to make it
work?
| > ||
| > || One other suggestion I got was to use a Hashtable with a structure.
The
| > || also seems like a good idea.
| > ||
| > || Rich
| > ||
| > || "Jay B. Harlow [MVP - Outlook]" wrote:
| > ||
| > || > Rich,
| > || > | I need to store some values in an array type collection object
that
| > | can
| > || > | hold 3 or more parameters per index.
| > || >
| > || > It sounds like you want a collection of collections. Is the outer
| > | collection
| > || > keyed or not keyed? Is the inner collection keyed or not keyed? In
| > other
| > || > words is row one known by a specific Key or simply as row one?
| > || >
| > || > | would prefer not to hassel with a multi-dimensional
| > || > | array.
| > || > Rather then a 2 dimensional array, have you considered an array of
| > | arrays?
| > || >
| > || > Dim block(10,10) as String ' 2 dimensional array each row = 10,
| > each
| > || > column is 10
| > || >
| > || > Dim jagged(10)() As String ' ragged/jagged array, 10 rows or 0
or
| > | more
| > || > elements.
| > || >
| > || >
| > || > Have you looked at the NameValueCollection?
| > || >
| > || >
| > |
| >
http://msdn.microsoft.com/library/d...sspecializednamevaluecollectionclasstopic.asp
| > || >
| > || > It associates a String Key with one or more String values. If your
| > | values
| > || > and/or keys are not strings NameValueCollection probably won't
work...
| > || >
| > || > | retrieve items
| > || > | s = obj.Item("parmA1", 1)
| > || > | t = obj.Item("parmA1", 2)
| > || > You may need to define a custom collection that encapsulates one of
the
| > || > above for storage.
| > || >
| > || > --
| > || > Hope this helps
| > || > Jay [MVP - Outlook]
| > || > ..NET Application Architect, Enthusiast, & Evangelist
| > || > T.S. Bradley -
http://www.tsbradley.net
| > || >
| > || >
| > || > | > || > | Yes, I need to store some values in an array type collection
object
| > | that
| > || > can
| > || > | hold 3 or more parameters per index. I have looked at the
collection
| > || > object,
| > || > | hashtable object and would prefer not to hassel with a
| > | multi-dimensional
| > || > | array. Is there such an object in VB.Net?
| > || > |
| > || > | Dim obj As someCollectionObj
| > || > | obj.Add("parmA1", "parmA2", "parmA3")
| > || > | obj.Add("parmB1", "parmB2", "parmB3")
| > || > | ...
| > || > |
| > || > | retrieve items
| > || > | s = obj.Item("parmA1", 1)
| > || > | t = obj.Item("parmA1", 2)
| > || > |
| > || > | or, can a Hashtable contain a hashtable?
| > || > |
| > || > | Thanks,
| > || > | Rich
| > || >
| > || >
| > || >
| > |
| > |
| >
| >
| >