Retrieving subsets from an ArrayList

  • Thread starter Thread starter Roshawn
  • Start date Start date
R

Roshawn

Hi,

How do you retrieve only a subset of items from an ArrayList using a
For...Next loop?

For instance, say I want to work only with 30 ArrayList items at a time.
After processing the 30 items, I'd like to retrieve the next 30 items and
process them. I'd like to continue doing it this way until all items have
been processed. How do I go about accomplishing this? I don't know where
to begin :-(

Thanks,
Roshawn
 
Hi Roshawn,

Here is how you would do it in nested loops.

Dim al As ArrayList
al = New ArrayList(100)
Dim i As Integer
For i = 0 To 100
al.Add(i)
Next

Dim cntOuter As Integer
Dim cntInner As Integer
Dim NOuter As Integer
Dim NInner As Integer = 30
Dim NTotal As Integer = al.Count

If NTotal > NInner Then
NOuter = Math.Ceiling(al.Count / NInner)
End If
Dim nStart As Integer = 0
Dim nEnd As Integer

For cntOuter = 1 To NOuter
nEnd = cntOuter * NInner - 1
If nEnd > NTotal - 1 Then nEnd = NTotal - 1
For cntInner = nStart To nEnd
'Process your data
Debug.WriteLine(al(cntInner).ToString)
Next
nStart = nEnd + 1
Next



Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
Back
Top