Prerequisites:
I've got:
- a
Collection
called "users
" - which consits of instances of a
Class
called "MatchClass
" - the "
MatchClass
" consists of only two properties -userid
andmatchArray
(plus some methods which are not relevant to the question)
What I want to do
Is to loop over the Collection
, while simultaneously being able to
- access the position within the collection
- access the properties of the class instance
- find the highest value out of all
matchArray
s (they are already sorted) and store theuserid
What I've tried so far:
To loop over the Collection
with a For Each
loop
Dim users as New Collection Dim i as Byte Dim max as Integer: max = 0 Dim maxuser as String ' users Collection is filled with instances of MatchClass ' ... skipping code to simplify ... Dim user as MatchClass For Each user in users temp = user.matchArray(0, 0) If temp > max Then max = temp maxuser = users.Item ' <- this won't work End If Next user
Then I can't acess the position of the
user
within theFor Each
loop
Alternatively I tried numerical looping:
For i = users.Count to 1 Step -1 users.Item(i).matchArray(0, 0) ' <- this won't work Next i
This unfortunately won't work either, as I can't access the properties of the
MatchClass
instances via theusers.Item(i)
code either.
Is there perhaps a best of both worlds solution where I can do both? Feels like it should be somethign arbitrary that I'm just missing.