p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Excel VBA (http://p2p.wrox.com/forumdisplay.php?f=79)
-   -   For....Loop (http://p2p.wrox.com/showthread.php?t=24951)

kliu9 February 2nd, 2005 04:16 PM

For....Loop
 
Hi -

I need to process every entry in an array. So I use the for...loop to do so. And inside the for..loop, I have several steps to process for each entry. However, if any of steps fails, I don't want to continue processing the rest of steps for that particular entry. But I want to go on and process next entry in the array with all the steps in the for...loop. How do I go about skipping rest of steps and go to the next entry? I read somewhere about having a label at the beginning of the statement where I can break out. But can't find it. Any solution is greatly appreciated.

Thanks.
Kathy

Vadivel February 3rd, 2005 01:15 AM

How about setting a boolean flag to false when some condition fails. Check this boolean flag before continuing with your other steps / process .. if its true don't process it.

0. Flag = true
1. For Loop
2. You Condition Fails --- so Flag = false
3. If Flag <> false Then
4. Rest of the processing comes here
5. If loop ends here
6. For loop ends here

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com

vemaju February 3rd, 2005 02:24 AM

Hi

Set the counter to the maximun value if the step fails

-vemaju


mjppaba February 3rd, 2005 07:37 AM

for myloop = 1 to 10 step 1
'processes go here...

if myprocess = false then goto endloop else continue...

EndLoop:
next

Using a label just before the cloisure of the next/loop functionality will allow you to conduct the tests and if a false result is the outcome you point to the EndLoop: label thus skipping any unwanted code.

Cheers
Matthew


kliu9 February 9th, 2005 03:29 PM

Matthew -

This works! Thank you.

Kathy


Quote:

quote:Originally posted by mjppaba
 for myloop = 1 to 10 step 1
'processes go here...

if myprocess = false then goto endloop else continue...

EndLoop:
next

Using a label just before the cloisure of the next/loop functionality will allow you to conduct the tests and if a false result is the outcome you point to the EndLoop: label thus skipping any unwanted code.

Cheers
Matthew



mjppaba February 10th, 2005 06:43 AM

Hi Kathy,

Your more than welcome.

M



All times are GMT -4. The time now is 02:04 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.