Public Class MyForEachBug
'
Public Class MyData
Public Element As String
Public Group() As String = {"a", "b", "c"}
End Class
'
Public Sub New()
'
Dim Element As String
Dim Group() As String = {"a", "b", "c"}
Dim D1 As New MyData
Dim D2 As New MyData
'
'
For Each Element In Group
For Each D1.Element In D1.Group
For Each D2.Element In D2.Group
Console.WriteLine _
( _
Element & D1.Element & D2.Element _
)
Next
Next
Next
End Sub
'
End Class
1. D1 is not instantiated
2. D2 is not instantiated
3. What is that that you are attempting to do?
a. Find every occurance of an item in Group, in d1.group and then in
d2.group?
b. Find every combination of the occurances in group, dr.group,
d2.group?
Here is an approach for a:
d1 = new myData: d1.element = string.empty: d1.group = new
string(){"a","B","c"}
d2 = new myData: d2.element = string.empty: d2.group = new
string(){"A","b","C"}
'Find the first index
For Each Element In Group
'Find the second index that matches the first index
For Each Element1 as string In D1.Group
If String.Compare(Element, Element1) = 0 Then
'Find the third index that matches the second index
For Each Element2 as string In D2.Group
If String.Compare(Element1, Element2) = 0 Then
'Inform us that the indexes has been found
Console.WriteLine(String.Format("Element 1:{0}, 2:{1}, 3:{0}",
Element, Element1, Element2))
Exit For
End If
Next
Exit For
End If
Next
Next
"crazyone" <th************@gmail.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
In my compiler it says "For loop control variable Element already in
use by an enclosing For Loop.
I think it's a bug in the compiler because it doesn't take into account
the fact that Element is part of D2 and not D1...
To Change this, you'll have to declare a second variable called
differently and use that one instead of D2.Element.
Math