Loop Problem

Tddupre

Member
Joined
May 12, 2009
Messages
5
Programming Experience
1-3
Currently I have 1 Loop that looks like this

For i = 0 To Number
<Insert Code Here>
Next

I need help with is adding a loop around that like

For each Item in listbox1
for i = 0 to number
msgbox(listbox1(item)
next
next

this isnt the actual code that will be in the loops, but it's the same premise. It just doesnt want to work, any help would be appreciated
 
Loops that start with 0 are good for arrays as they start with 0 and end in the .count -1.
VB.NET:
For i As Integer = 0 To Listbox1.Items.Count -1
   'do something
Next

Loop thru a listbox like this:
VB.NET:
For Each str As String In Listbox1.Items
   'do something
Next
 
I just tested this in a console and it works just great:

VB.NET:
        Dim A As Integer
        Dim innerB As Integer

        For A = 0 To 10
            For innerB = 15 To 20
                Console.WriteLine(A & " - " & innerB)
            Next
        Next

I think newguy hit on your solution! if you loop from 0 to the count of items you have, you will get one too many, so subtracting one from the count will give you the right quantity of loops.
 
Back
Top