Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 2nd, 2005, 04:16 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
  #2 (permalink)  
Old February 3rd, 2005, 01:15 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

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
  #3 (permalink)  
Old February 3rd, 2005, 02:24 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: , , Finland.
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Set the counter to the maximun value if the step fails

-vemaju

  #4 (permalink)  
Old February 3rd, 2005, 07:37 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: Bournemouth, Dorset, United Kingdom.
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #5 (permalink)  
Old February 9th, 2005, 03:29 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #6 (permalink)  
Old February 10th, 2005, 06:43 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: Bournemouth, Dorset, United Kingdom.
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Kathy,

Your more than welcome.

M



Similar Threads
Thread Thread Starter Forum Replies Last Post
Do Loop stealthdevil Access VBA 5 October 5th, 2006 01:22 PM
Help with for-each loop athanatos XSLT 0 April 10th, 2006 07:20 PM
Do Until loop with IF crmpicco Classic ASP Databases 2 June 15th, 2005 05:35 PM
Do Loop junemo Beginning PHP 8 July 28th, 2004 02:58 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





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