By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Why my For Each block does not work?

!NoItAll
100+
P: 296
This one is really perplexing me...
First some working stats...
  • Visual Studio 2015
  • Visual Basic .NET
  • Framework 4.6.1
  • Windows 10 x64
I have a small codeblock
Expand|Select|Wrap|Line Numbers
  1. For Each src As CommonStructures.Source_Type In SourcesConfig.Sources.Source
  2.     ManageImageAndLatestFolders(src, ActionEnum.Add)
  3. Next
  4.  
Intellesense indicates there are 8 elements of the SourcesConfig.Sources.Source object and that the types are derived from the same class (not duplicates, the same class). With the above block the ManageImageAndLatestFolders sub is never called!

However...

The same block of code works just fine

Expand|Select|Wrap|Line Numbers
  1. For I as Integer = 0 to (SourcesConfig.Sources.Source - 1)
  2.     ManageImageAndLatestFolders(SourcesConfig.SOurces.Source(I), ActionEnum.Add)
  3. Next I
  4.  
Although the form is different, the two routines above are identical in function. The For Each block, however, does not iterate through the src items (of which there are clearly 8).
I have tried to clean the application(Build -> Clean [Project]).
Any thoughts from anyone? What might I be missing?

I use For Each in lots of places in my code - and because of this anomaly I am afraid I'm doing something wrong that might be affecting much of my work!
Jan 5 '17 #1
Share this Question
Share on Google+
2 Replies


!NoItAll
100+
P: 296
Well - more information...
It actually is executing as it should, but the debugger simply does not step into it the way I expect it to. If I put a breakpoint inside of the ManageImageAndLatestFolders sub, it runs 8 times - however when stepping through the code it never steps onto the ManageImageAndLatestFolders sub!
This seems like a Visual Studio bug to me. I've checked all of the Debugging options and find nothing obvious...
Jan 5 '17 #2

Frinavale
Expert Mod 5K+
P: 9,731
What is SourcesConfig.Sources.Source??

In the first code block you are using it like an array or collection of some sort:
Expand|Select|Wrap|Line Numbers
  1. For Each src As CommonStructures.Source_Type In SourcesConfig.Sources.Source
In the second code block you are using it like an integer and subtracting one from it:

Expand|Select|Wrap|Line Numbers
  1. For I as Integer = 0 to (SourcesConfig.Sources.Source - 1)
If it is an integer, then your foreach obviously won't work because it's not a collection...

Maybe your foreach should be as follows??
Expand|Select|Wrap|Line Numbers
  1. For Each src As CommonStructures.Source_Type In SourcesConfig.Sources
But then again, you are treating it like an array/collection here:

Expand|Select|Wrap|Line Numbers
  1. ManageImageAndLatestFolders(SourcesConfig.SOurces.Source(I), ActionEnum.Add)
It would help to know what things are. Also if you are using structures or classes?

-Frinny
Jan 11 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.