Yes, there is a way. First, here's a sample Account and Accounts (without any error handling):
Option Explicit On
Option Strict On
Public Class Account
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
' More properties
End Class
Public Class Accounts
Private m_coll As List(Of Account)
Public Sub New()
'
' Initialize class
m_coll = New List(Of Account)
End Sub
Protected Overrides Sub Finalize()
'
' Terminate
'
MyBase.Finalize()
End Sub
' LOTS of more code to save, load, add , remove etc. items
Public Function Item(ByVal Index As Integer) As Account
'
' Return a record from the collection
Return CType(m_coll.Item(Index), Account)
End Function
Public Function Count() As Integer
'
' Return the number of records in the collection
Return m_coll.Count
End Function
End Class
and now you can loop the collection:
Dim x As Integer
Dim obj As Account
Dim col As Accounts
col = New Accounts
' Fill col with data
For x = 0 To col.Count - 1
obj = col.Item(x)
MessageBox.Show(obj.Name, "Collection Item", MessageBoxButtons.OK, MessageBoxIcon.Information)
Next x
Notice that all collections and arrays start in .NET from index = 0, not from 1 like in VB6. This sample used a List( Of ), there's a few more collection types you can use.
When you get really into .NET collections, search examples how to use IEnumerable and IEnumerator interfaces. Then you can use
For Each obj In col
MessageBox.Show(obj.Name, "Collection Item", MessageBoxButtons.OK, MessageBoxIcon.Information)
Next syntax in your code.