Implementing MoveFirst(), MoveLst() etc into collection...

G

Guest

Hi,

I have been passed a class to work with, but am having some problems. I do
not know the origin of the code, and am having problems with some
functionality.

The VB class implements IEnumerable, which I understand allows for fwd only
movement through the custtom collection. This work fine and I am able to use
"For Each" loops without issue. However, the class has MoveFirst(),
MoveLast() etc methods within it, but these do not appear to be exposed, and
are therefore unavailable. Is the IEnumerable interface restricting these
methods somehow, or is the class missing elements.

So, How do I implement MoveFirst(), MoveNext() with the following class(s)?

Many Thanks,

Duncan.

************************************************************
Imports Microsoft.VisualBasic

Public Class Raters
Implements System.Collections.IEnumerable

Private m_Raters As ArrayList = New ArrayList
Private m_CurrentIndex As Integer = -1
Private m_Count As Integer = 0
Private m_CandidateId As Integer = 0

Public ReadOnly Property Count() As Integer
Get
Return m_Count
End Get
End Property

Public Sub Add(ByVal Rater As Rater)
m_Raters.Add(Rater)
m_Count += 1
End Sub

Public Function GetEnumerator() As System.Collections.IEnumerator
Implements System.Collections.IEnumerable.GetEnumerator
Return New RatersEnumerator(Me)
End Function

Public Function MoveNext() As Boolean
Me.GetEnumerator.MoveNext()
End Function

Public Function MoveFirst() As Boolean
'*???*
End Function

Public Class RatersEnumerator
Implements IEnumerator

Private m_Raters As Raters

Public Sub New(ByVal Raters As Raters)
m_Raters = Raters
Me.Reset()
End Sub

Public ReadOnly Property Current() As Object Implements
System.Collections.IEnumerator.Current
Get
Return m_Raters.m_Raters(m_Raters.m_CurrentIndex)
End Get
End Property

Public Function MoveNext() As Boolean Implements
System.Collections.IEnumerator.MoveNext
If (m_Raters.m_CurrentIndex = (m_Raters.m_Raters.Count - 1)) Then
Return False
Else
m_Raters.m_CurrentIndex += 1
Return True
End If
End Function

Public Function MovePrevious() As Boolean
If (m_Raters.m_CurrentIndex = (m_Raters.m_Raters.Count + 1)) Then
Return False
Else
m_Raters.m_CurrentIndex -= 1
Return True
End If
End Function

Public Function MoveFirst() As Boolean
If (m_Raters.m_Raters.Count() <> -1) Then
m_Raters.m_CurrentIndex = 0
Else
m_Raters.m_CurrentIndex = -1
End If
End Function

Public Function MoveLast() As Boolean
If (m_Raters.m_Raters.Count() <> -1) Then
m_Raters.m_CurrentIndex = m_Raters.m_Raters.Count
Else
m_Raters.m_CurrentIndex = -1
End If
End Function

Public ReadOnly Property Count() As Integer
Get
Return m_Raters.m_Raters.Count()
End Get
End Property

Public Sub Reset() Implements System.Collections.IEnumerator.Reset
m_Raters.m_CurrentIndex = -1
End Sub
End Class

End Class
************************************************************
 
G

Guest

By moving the MoveFirst() method into the Raters class itself and remiving
the 1st m_Raters reference (not the RatersEnumerator class) I think I may
have solved the first issue, however I need to test this.

I'd also to be able to access the collection as object.Raters(i).value

How do I add indexing to this object?

Any pointers on this?

Regards

Duncan
 
G

Guest

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top