Why my For Each block does not work?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • !NoItAll
    Contributor
    • May 2006
    • 297

    Why my For Each block does not work?

    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
    Code:
    For Each src As CommonStructures.Source_Type In SourcesConfig.Sources.Source
        ManageImageAndLatestFolders(src, ActionEnum.Add)
    Next
    Intellesense indicates there are 8 elements of the SourcesConfig.S ources.Source object and that the types are derived from the same class (not duplicates, the same class). With the above block the ManageImageAndL atestFolders sub is never called!

    However...

    The same block of code works just fine

    Code:
    For I as Integer = 0 to (SourcesConfig.Sources.Source - 1)
        ManageImageAndLatestFolders(SourcesConfig.SOurces.Source(I), ActionEnum.Add)
    Next I
    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(Bui ld -> 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!
    Last edited by !NoItAll; Jan 5 '17, 02:55 PM. Reason: small clarification
  • !NoItAll
    Contributor
    • May 2006
    • 297

    #2
    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 ManageImageAndL atestFolders sub, it runs 8 times - however when stepping through the code it never steps onto the ManageImageAndL atestFolders sub!
    This seems like a Visual Studio bug to me. I've checked all of the Debugging options and find nothing obvious...

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      What is SourcesConfig.S ources.Source??

      In the first code block you are using it like an array or collection of some sort:
      Code:
      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:

      Code:
      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??
      Code:
      For Each src As CommonStructures.Source_Type In SourcesConfig.Sources
      But then again, you are treating it like an array/collection here:

      Code:
      ManageImageAndLatestFolders(SourcesConfig.SOurces.Source(I), ActionEnum.Add)
      It would help to know what things are. Also if you are using structures or classes?

      -Frinny

      Comment

      Working...