Solved

Is there a special VB statement  to let you jump to the next iteration in a loop?

Posted on 2006-11-21
5
188 Views
Last Modified: 2010-04-30
Jump to next iteration in a loop

Say you got a loop like the one below.  How do I accomplish the same task without the goto statement?

  For Each MyControl In ControlCollection
    If TypeOf MyControl Is Whatever Then Goto SkipThisOne
    ' Provide code here to work with valid MyControl
SkipThisOne:
  Next MyControl

And, NO - I do NOT mean do as follows...

For Each MyControl In ControlCollection
        If not TypeOf MyControl Is Whatever Then
        ' Provide code here to work with valid MyControl
       end if
       Next MyControl

tia

avi

 
 
0
Comment
Question by:progtw
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:drydenhogg
ID: 17985818
In terms of a built in collection type used in a for..each loop basically no. You have the choices of using program flow logic or goto statements, the latter of which I would say never use.


0
 
LVL 8

Assisted Solution

by:doobdave
doobdave earned 40 total points
ID: 17985895
Hi,
What's wrong with using the second method:
For Each MyControl In ControlCollection
        If not TypeOf MyControl Is Whatever Then
        ' Provide code here to work with valid MyControl
       end if
       Next MyControl
?

It looks like a much better solution than using thhe goto statement.

Best Regards,

David
0
 

Author Comment

by:progtw
ID: 17985937
to doobdave:

>> What's wrong with using the second method:

But there isn't a special VB statement  to let you jump to the next iteration in a loop?

avi
0
 
LVL 8

Accepted Solution

by:
drydenhogg earned 85 total points
ID: 17985955
There is no special statement that allows you to skip to next, no.
0
 

Author Comment

by:progtw
ID: 17985974
foooo-ey!

avi
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to debug this code 7 61
Spell Check in VB6 13 113
how to know if my Checkbox is True in VB6.0? 9 55
MsgBox 4 61
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question