Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Stopping a For Next Loop until a value is return from another form

Question posted by: pfildes (Newbie) on July 25th, 2008 03:18 AM
Hi,

I am pretty new to VB.net and am having trouble figuring out how to do this.

I have an app that copies data from one datasource to another.

I have it set to run through a for loop for each row in SourceDataTable.

for each row i get the a value that is not an ID and I have a funciton that compares this to a column in the Destination, and i recieve the ID back if it exits and nothing if it doesn't. This work fine the next part I am having trouble with.

I then have an IF statement that test if the ID is returned or not then chooses whether to run the Insert if it does exist or If the ID doesn't exist i want to open up a form where i can choose (and return) the ID i want to use (i know how to set all this up)

the problem i am having is that i the for loop that is transferring data from the source to the destination keeps going.

here is the for loop i am using, i just need to know how to stop the loop from running while i am retrieving strID from a new form. i have put this bit in red

Code: ( text )
  1. For i = 0 To dbDataTable.Rows.Count - 1
  2.  
  3. 'get the value for the ID to compare
  4. str1 = dbDataTable.Rows(i)(0).ToString
  5. str1 = Replace(str1, "'", "")
  6.  
  7. 'compare the source ID to the destination ID column to see if it is to be update or insert
  8. strID = Compares.ReturnDestinationID(dbDestinationDataset,   str1)
  9.  
  10. If strID = "" Then
  11.  
  12. 'open form for retrieving ID to use for insert
  13. strID = Value recieved back from other form
  14.  
  15. 'run insert sub using the new strID
  16. Inserts.InsertDataRowToDestination(dbDataTable.Row  s(i), strID)
  17.  
  18. Else
  19.  
  20. 'this is a sub I have created to insert the data row to the destination table
  21. Inserts.InsertDataRowToDestination(dbDataTable.Row  s(i), strID)
  22.  
  23. End If
  24.  
  25. Next


any direction will be very greatly appreciated
Last edited by DrBunchman : July 25th, 2008 at 08:05 AM. Reason: Added [Code] Tags - Please use the '#' button
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
DrBunchman's Avatar
DrBunchman
Moderator
763 Posts
July 25th, 2008
08:06 AM
#2

Re: Stopping a For Next Loop until a value is return from another form
Hi pfildes,

You can use
Code: ( text )
  1. Exit For

to stop the loop.

Hope this helps,

Dr B

Reply
Reply
Not the answer you were looking for? Post your question . . .
184,011 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top .NET Forum Contributors