none
Reset a "For Each" loop so it restarts from the beginning?

    Question

  • I have a "For Each" loop that reads the filenames in a folder:

    For Each foundFile As String In My.Computer.FileSystem.GetDirectories(Src)
    .

    Works fine the first time through. But if the user tries to run the program again, it thinks it's already read the list and causes an error.

    Is there a way to reset the loop so it starts from the beginning again?

    TIA

    Tuesday, May 21, 2019 8:28 PM

Answers

  • Hi

    It doesn't think it has already done it! That isn't the way things work.

    There is no need to 'reset' the loop as every time it encounters it, it will start as though it is the first time.

    You will need to post the entire loop so we can see what is going on in it.

    *

    BTW: anytime you feel the need to include the words 'causes an error', you need to post the actual exception message too.


    Regards Les, Livingston, Scotland


    • Edited by leshay Tuesday, May 21, 2019 8:57 PM
    • Marked as answer by Mugsy_in_Houston Friday, May 24, 2019 10:48 AM
    Tuesday, May 21, 2019 8:56 PM

All replies

  • Hi

    It doesn't think it has already done it! That isn't the way things work.

    There is no need to 'reset' the loop as every time it encounters it, it will start as though it is the first time.

    You will need to post the entire loop so we can see what is going on in it.

    *

    BTW: anytime you feel the need to include the words 'causes an error', you need to post the actual exception message too.


    Regards Les, Livingston, Scotland


    • Edited by leshay Tuesday, May 21, 2019 8:57 PM
    • Marked as answer by Mugsy_in_Houston Friday, May 24, 2019 10:48 AM
    Tuesday, May 21, 2019 8:56 PM
  • It doesn't think it has already done it! That isn't the way things work.
    .
    Thanks. I will provide a screenshot of the error message later (Working on something else ATM.)
    Tuesday, May 21, 2019 9:37 PM
  • It doesn't think it has already done it! That isn't the way things work.

    .
    Thanks. I will provide a screenshot of the error message later (Working on something else ATM.)

    Hi,

    Please provide your screenshot so we can assist you.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 23, 2019 5:05 AM
    Moderator