473,480 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can't get a working collection!

I want to store data pertaining to a widget in a collection. The widget has
many pproperties, so i created the following class and called it
"clsWatchProperties":

Public Class clsWatchProperties

Private mTopicID As Integer

Private mLastPos As Integer

Private mThisPos As Integer

Private mCancelThisItem As Boolean

Private mHasNewReply As Boolean

Public Property TopicID() As Integer

Get

TopicID = mTopicID

End Get

Set(ByVal Value As Integer)

mTopicID = Value

End Set

End Property

Public Property LastPos() As Integer

Get

LastPos = mLastPos

End Get

Set(ByVal Value As Integer)

mLastPos = Value

End Set

End Property

Public Property ThisPos() As Integer

Get

ThisPos = mThisPos

End Get

Set(ByVal Value As Integer)

mThisPos = Value

End Set

End Property

Public Property CancelThisItem() As Boolean

Get

CancelThisItem = mCancelThisItem

End Get

Set(ByVal Value As Boolean)

mCancelThisItem = Value

End Set

End Property

Public Property HasNewReply() As Boolean

Get

HasNewReply = mHasNewReply

End Get

Set(ByVal Value As Boolean)

mHasNewReply = Value

End Set

End Property

End Class

I then (attempted to) create the collection using the following code:

Private WatchedTopics As New Collection

------

Sub Test

....

Dim WatchTopic As New clsWatchProperties

GetData = CleanString(mLink.ToString, CleanupHTML.ID) ' Retrieves
a 5 digit number which is in a string format

Debug.WriteLine("ID: " & GetData)

If Not FindIfExists(GetData, RowCounter) Then ' This line simply
checks if the object exists in the collection. True is returned if it does.

WatchTopic.TopicID = GetData

WatchTopic.LastPos = RowCounter

WatchTopic.HasNewReply = False

WatchedTopics.Add(WatchTopic,
WatchTopic.TopicID.ToString)

ThisItemIsUpdated = True

End If

If WatchedTopics.Item(GetData).HasNewReply Then

........

End If

I want my collection to look like this:

WatchedTopics("01234").LastPos = 100
WatchedTopics("04321").HasNewReply = False
WatchedTopics("09876").CancelThisItem = True

What I'm ACTUALLY getting is:

- WatchedTopics {Length=1} Microsoft.VisualBasic.Collection
(0) "Empty placeholder to adjust for 1 based array" String
- (1) {Microsoft.VisualBasic.Collection.KeyValuePair}
Microsoft.VisualBasic.Collection.KeyValuePair
- Key "107348" {String} Object
String "107348" String
- Value {rnsVBCityForumListener.clsWatchProperties} Object
- [rnsVBCityForumListener.clsWatchProperties]
{rnsVBCityForumListener.clsWatchProperties}
rnsVBCityForumListener.clsWatchProperties
CancelThisItem False Boolean
HasNewReply False Boolean
LastPos 1 Integer
mCancelThisItem False Boolean
mHasNewReply False Boolean
mLastPos 1 Integer
mThisPos 0 Integer
mTopicID 107348 Integer
ThisPos 0 Integer
TopicID 107348 Integer

(This is a copy and paste of the WatchTopics variable and its structure as
seen in the Watch window)
I think I have stuffed up in my code somewhere but can't figger out where.
Please help me.

--
|
+-- Thief_
|
Nov 21 '05 #1
3 3949
Thief,

Unlucky enough is the Visual.Basic collection not placed in the VisualBasic
compatible namespace however in the normal namespace. This means that it is
still active. However it is not the nicest collection to use, by instance
does it starts at First as indexer and gives therefore a lot of
complications. This is probably one of the reason that it is seldom used by
visitors/repliers from this newsgroup.

Have a look at all the collections that implement Ilist or/and Icollection
or those that are in System.Data

http://msdn.microsoft.com/library/de...classtopic.asp

As a second advice. Past in your samples first in a notebook copy them back
and than again in a message. You will see that you get more good answers
because your problems become readable.

I hope this helps,

Cor
Nov 21 '05 #2
Hi,

You might be better off using a hashtable instead of a
collection.

http://msdn.microsoft.com/library/de...classtopic.asp

Ken
-----------------
"Thief_" <th****@hotmail.com> wrote in message
news:eI**************@TK2MSFTNGP09.phx.gbl...
I want to store data pertaining to a widget in a collection. The widget has
many pproperties, so i created the following class and called it
"clsWatchProperties":

Public Class clsWatchProperties

Private mTopicID As Integer

Private mLastPos As Integer

Private mThisPos As Integer

Private mCancelThisItem As Boolean

Private mHasNewReply As Boolean

Public Property TopicID() As Integer

Get

TopicID = mTopicID

End Get

Set(ByVal Value As Integer)

mTopicID = Value

End Set

End Property

Public Property LastPos() As Integer

Get

LastPos = mLastPos

End Get

Set(ByVal Value As Integer)

mLastPos = Value

End Set

End Property

Public Property ThisPos() As Integer

Get

ThisPos = mThisPos

End Get

Set(ByVal Value As Integer)

mThisPos = Value

End Set

End Property

Public Property CancelThisItem() As Boolean

Get

CancelThisItem = mCancelThisItem

End Get

Set(ByVal Value As Boolean)

mCancelThisItem = Value

End Set

End Property

Public Property HasNewReply() As Boolean

Get

HasNewReply = mHasNewReply

End Get

Set(ByVal Value As Boolean)

mHasNewReply = Value

End Set

End Property

End Class

I then (attempted to) create the collection using the following code:

Private WatchedTopics As New Collection

------

Sub Test

....

Dim WatchTopic As New clsWatchProperties

GetData = CleanString(mLink.ToString, CleanupHTML.ID) ' Retrieves
a 5 digit number which is in a string format

Debug.WriteLine("ID: " & GetData)

If Not FindIfExists(GetData, RowCounter) Then ' This line simply
checks if the object exists in the collection. True is returned if it does.

WatchTopic.TopicID = GetData

WatchTopic.LastPos = RowCounter

WatchTopic.HasNewReply = False

WatchedTopics.Add(WatchTopic,
WatchTopic.TopicID.ToString)

ThisItemIsUpdated = True

End If

If WatchedTopics.Item(GetData).HasNewReply Then

........

End If

I want my collection to look like this:

WatchedTopics("01234").LastPos = 100
WatchedTopics("04321").HasNewReply = False
WatchedTopics("09876").CancelThisItem = True

What I'm ACTUALLY getting is:

- WatchedTopics {Length=1} Microsoft.VisualBasic.Collection
(0) "Empty placeholder to adjust for 1 based array" String
- (1) {Microsoft.VisualBasic.Collection.KeyValuePair}
Microsoft.VisualBasic.Collection.KeyValuePair
- Key "107348" {String} Object
String "107348" String
- Value {rnsVBCityForumListener.clsWatchProperties} Object
- [rnsVBCityForumListener.clsWatchProperties]
{rnsVBCityForumListener.clsWatchProperties}
rnsVBCityForumListener.clsWatchProperties
CancelThisItem False Boolean
HasNewReply False Boolean
LastPos 1 Integer
mCancelThisItem False Boolean
mHasNewReply False Boolean
mLastPos 1 Integer
mThisPos 0 Integer
mTopicID 107348 Integer
ThisPos 0 Integer
TopicID 107348 Integer

(This is a copy and paste of the WatchTopics variable and its structure as
seen in the Watch window)
I think I have stuffed up in my code somewhere but can't figger out where.
Please help me.

--
|
+-- Thief_
|

Nov 21 '05 #3
Below is the best example that I've seen on using a collection class...I got
it from someone on this newsgroup:

Public Class rectangle_Collection
Inherits CollectionBase
#Region "Property interface"
Public Shadows Property item(ByVal iIndex As Integer) As Rectangle
Get
If ((Count = 0) OrElse ((iIndex < 0) And (iIndex > (Count -
1)))) Then
Return (Nothing)
Else
Return (CType(innerlist.Item(iIndex), Rectangle))
End if
End Get
Set(ByVal Value As Rectangle)
If ((Count = 0) OrElse ((iIndex < 0) And (iIndex > (Count -
1)))) Then
Return
Else
innerlist.Item(iIndex) = Value
End If
End Set
End Property

#End Region

#Region "Public methods"

Public Function add(ByVal iRectangle As Rectangle) As Integer
Return innerlist.Add(iRectangle)
End Function

Public Sub addRange(ByVal iRectangle() As Rectangle)
Call innerlist.AddRange(iRectangle)
End Sub

Public Sub addRange(ByVal iRectangleCollection As rectangle_Collection)
Call innerlist.AddRange(iRectangleCollection)
End Sub

Public Function contains(ByVal iRectangle As Rectangle) As Boolean
Return (innerlist.Contains(iRectangle))
End Function

Public Function indexOf(ByVal iRectangle As Rectangle) As Integer
Return (innerlist.IndexOf(iRectangle))
End Function

Public Sub insert(ByVal iIndex As Integer, ByVal iRectangle As
Rectangle)
Call innerlist.Insert(iIndex, iRectangle)
End Sub

Public Sub insertRange(ByVal iIndex As Integer, ByVal iRectangle() As
Rectangle)
Call innerlist.InsertRange(iIndex, iRectangle)
End Sub

Public Sub insertRange(ByVal iIndex As Integer, ByVal
iRectangleCollection As rectangle_Collection)
Call innerlist.InsertRange(iIndex, iRectangleCollection)
End Sub

Public Function lastIndexOf(ByVal iRectangle As Rectangle) As Integer
Return (innerlist.LastIndexOf(iRectangle))
End Function

Public Sub remove(ByVal iRectangle As Rectangle)
Call innerlist.Remove(iRectangle)
End Sub

Public Sub Sort()
MyBase.InnerList.Sort()
End Sub

NOTE: To Trim the Collection:
Public Sub TrimResults(ByVal iElementsToKeep As Integer)
Dim myArray(iElementsToKeep-1) As clsMyClass
MyBase.InnerList.CopyTo(0, myArray, 0, iElementsToKeep)
MyBase.InnerList.Clear()
MyBase.InnerList.SetRange(0, myArray)
End Sub

#End Region
End Class

--
Dennis in Houston
"Ken Tucker [MVP]" wrote:
Hi,

You might be better off using a hashtable instead of a
collection.

http://msdn.microsoft.com/library/de...classtopic.asp

Ken
-----------------
"Thief_" <th****@hotmail.com> wrote in message
news:eI**************@TK2MSFTNGP09.phx.gbl...
I want to store data pertaining to a widget in a collection. The widget has
many pproperties, so i created the following class and called it
"clsWatchProperties":

Public Class clsWatchProperties

Private mTopicID As Integer

Private mLastPos As Integer

Private mThisPos As Integer

Private mCancelThisItem As Boolean

Private mHasNewReply As Boolean

Public Property TopicID() As Integer

Get

TopicID = mTopicID

End Get

Set(ByVal Value As Integer)

mTopicID = Value

End Set

End Property

Public Property LastPos() As Integer

Get

LastPos = mLastPos

End Get

Set(ByVal Value As Integer)

mLastPos = Value

End Set

End Property

Public Property ThisPos() As Integer

Get

ThisPos = mThisPos

End Get

Set(ByVal Value As Integer)

mThisPos = Value

End Set

End Property

Public Property CancelThisItem() As Boolean

Get

CancelThisItem = mCancelThisItem

End Get

Set(ByVal Value As Boolean)

mCancelThisItem = Value

End Set

End Property

Public Property HasNewReply() As Boolean

Get

HasNewReply = mHasNewReply

End Get

Set(ByVal Value As Boolean)

mHasNewReply = Value

End Set

End Property

End Class

I then (attempted to) create the collection using the following code:

Private WatchedTopics As New Collection

------

Sub Test

....

Dim WatchTopic As New clsWatchProperties

GetData = CleanString(mLink.ToString, CleanupHTML.ID) ' Retrieves
a 5 digit number which is in a string format

Debug.WriteLine("ID: " & GetData)

If Not FindIfExists(GetData, RowCounter) Then ' This line simply
checks if the object exists in the collection. True is returned if it does.

WatchTopic.TopicID = GetData

WatchTopic.LastPos = RowCounter

WatchTopic.HasNewReply = False

WatchedTopics.Add(WatchTopic,
WatchTopic.TopicID.ToString)

ThisItemIsUpdated = True

End If

If WatchedTopics.Item(GetData).HasNewReply Then

........

End If

I want my collection to look like this:

WatchedTopics("01234").LastPos = 100
WatchedTopics("04321").HasNewReply = False
WatchedTopics("09876").CancelThisItem = True

What I'm ACTUALLY getting is:

- WatchedTopics {Length=1} Microsoft.VisualBasic.Collection
(0) "Empty placeholder to adjust for 1 based array" String
- (1) {Microsoft.VisualBasic.Collection.KeyValuePair}
Microsoft.VisualBasic.Collection.KeyValuePair
- Key "107348" {String} Object
String "107348" String
- Value {rnsVBCityForumListener.clsWatchProperties} Object
- [rnsVBCityForumListener.clsWatchProperties]
{rnsVBCityForumListener.clsWatchProperties}
rnsVBCityForumListener.clsWatchProperties
CancelThisItem False Boolean
HasNewReply False Boolean
LastPos 1 Integer
mCancelThisItem False Boolean
mHasNewReply False Boolean
mLastPos 1 Integer
mThisPos 0 Integer
mTopicID 107348 Integer
ThisPos 0 Integer
TopicID 107348 Integer

(This is a copy and paste of the WatchTopics variable and its structure as
seen in the Watch window)
I think I have stuffed up in my code somewhere but can't figger out where.
Please help me.

--
|
+-- Thief_
|

Nov 21 '05 #4

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

Similar topics

7
1200
by: noticias.mad.ttd.net | last post by:
Hello. Some days ago I posted a message about this (somebody replied asking me if I was using IE, but I am using Mozilla 1.7.5): This 'for' statment works for me, i.e.: for (var i =...
39
6473
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
25
2345
by: Zeng | last post by:
I finally narrowed down my code to this situation, quite a few (not all) of my CMyClass objects got hold up after each run of this function via the simple webpage that shows NumberEd editbox. My...
5
3560
by: Jeff Johnson | last post by:
I'm using forms authentication to protect a subfolder within my site. I've got it working fine except for two issues: (1) When I do a RedirectFromLogin page I have to put a cookie path ("/"...
9
2069
by: Christian Blackburn | last post by:
Hi Gang, I've had this happen with a couple of controls now, but my patience has worn thin. Can somebody tell me why I can read/write to most objects on my form from my module, but not when...
4
1538
by: MAF | last post by:
I have a collection setup as a queque collection and when I attempt to deque the collection I get two objects off of the collection instead of one. This usually happens the first time I attempt to...
2
16331
by: Rob Roberts | last post by:
I have a GridView that is bound to a collection of DateTimes (i.e. - Collection<DateTime>). I have a BoundField in the GridView, and its DataField is set to the DateTime's Date property, and the...
3
1637
by: Matt | last post by:
I am in the process of creating a custom .NET object (this is my first one). I have created a few classes and some of them are collections. When I try to iterate through a collection I receive the...
19
1511
by: Barry Mossman | last post by:
Hi, if I have a generic class such as: public class MyGroup<T> : Collection<MyChildClass> and from one of it's methods I want to pass a reference to myself to the following method in another...
0
7046
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
6908
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
7088
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...
1
6741
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
6956
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...
0
5342
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4783
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.