473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

My for each loops do not compile - VB 2003


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

Aug 11 '06 #1
5 1059
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

Aug 11 '06 #2

"IanT" <Ia**@discussions.microsoft.comwrote in message
news:62**********************************@microsof t.com...
>
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
Could you share exactly what compiler error(s) you got and at which line(s)?
Aug 11 '06 #3
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

Aug 11 '06 #4
Yes that's the error I get.
And I agree, its a compiler short circuit.

If the VB really did not support dot names then
"D1.Element" should fail because "Element" was already used.

"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

Aug 11 '06 #5
Hello IanT,

usually you declare your loop index variables outside of the class. You
declare them where you are going to use them.

-Boo
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

Aug 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
80
by: | last post by:
Is there a performance difference between this: \\\ Dim i As Integer For i = 0 to myObject.Controls.Count - 1 myObject.Controls(i) = ... Next /// and this:
15
by: Steven T. Hatton | last post by:
It blows up on a 9 dimensional space, but I'm pretty sure that's due to the size of size_t. --- begin: DataGeneration_Test --- Tensor<T 3, 3>...
9
by: Geoff Jones | last post by:
Hi Suppose I have a For Each loop, for example, For Each x As DataRow In drMyData ' Do stuff - calculation 1 ' Do more stuff - calculation 2 ' and even more stuff - calculation 3 Next
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
6
by: Neal | last post by:
Hi All, I used an article on XSLT and XML and creating a TOC written on the MSDN CodeCorner. ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dncodecorn/html/corner042699.htm However, it did'nt...
7
by: paolo.arimado | last post by:
Dear everyone, Can someone please help me on my HW. I'm trying to write a program that will display the following: * *** ***** ******* *********
6
by: looping | last post by:
Hi, Probably not the best group to post my question but I'm sure there is some people here that use Twisted. First here is the beginning of my source code: from twisted.internet import reactor,...
2
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.