For Each Loop Problems

cpopham

Junior Contributor
Joined
Feb 18, 2004
Messages
273
I am looping thought all of the files in a directory. Easy enough, now I am putting the file name of each file in a textbox for my user to check as the loop goes through each file. After the user verifies the file, they press a button to continue to the file in the loop. My question is, how can I get my loop to stop at each file after putting the file info in the textbox and then waiting for my user to click OK. I guess I want the loop to pause when it gets to the user verification point and then resume when the user presses the button. Any ideas?

Thanks, Chester
 
A message box might be one way you could do this.

Visual Basic:
 'This is a blocking call
If MessageBox.Show("Do you want this file?", "Well, do you?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
   MessageBox.Show("Keep the file!")
Else
   MessageBox.Show("Ditch the file!")
End If

...
 
You can also create your own intermediate form and call the ShowDialog function of that form, which pauses execution on the calling thread until the form is hidden or closed.

A third option would be a multithreaded approach, where you could load all the files on a secondary (non-gui) thread and for each file, block the thread until the user clicks OK for each file. At this point, though, there would also be single-threaded options that could also provide the same functionality.
 
I think what I am going to do is either use a hidden list box or an array that contains will store the file names. I will then have a module level variable that will keep track of the file that is currently being check. When the user clicks okay for the file, I will have the sub get the current count from the vairable, add one to it and then go to that file. I think that may be the most simple way of implementing it.

Thanks for the help guys!

Chester
 
Back
Top