Home All Groups Group Topic Archive Search About

On Error Goto Next Loop

Author
18 Oct 2006 7:27 AM
Lucia
Hi, everyone,

I have a for statement in my programm. I want to know if there is any
way to goto next i when some error occurs. I tried with the following
code. But it doesn't work...

for i=0 to 100

On Error Goto NEXTFOR

.....

NEXTFOR:
next

thanks a lot

Lucia

Author
18 Oct 2006 7:55 AM
Patrice
Works here. What is the error you try to catch ? My first thought would be
that this is actually not considered as an error...

Actually I'm not using this style anymore. My personal preference would be
to use try catch. Also if this is something that can be controlled before
hand I prefer to test that the statement won't raise an error before issuing
it, rather than letting the error happens and handle it afterward...

--
Patrice

"Lucia" <cheng_lu***@yahoo.com> a écrit dans le message de news:
1161156478.770535.234***@m7g2000cwm.googlegroups.com...
Show quoteHide quote
> Hi, everyone,
>
> I have a for statement in my programm. I want to know if there is any
> way to goto next i when some error occurs. I tried with the following
> code. But it doesn't work...
>
> for i=0 to 100
>
> On Error Goto NEXTFOR
>
> ....
>
> NEXTFOR:
> next
>
> thanks a lot
>
> Lucia
>
Author
18 Oct 2006 8:24 AM
Norman Chong
Patrice schrieb:

Try-Catch-blocks are better than GOTOs, especially when you need a lot
of error-handling - When you have 150 different error-handlers within a
project, you might get a little confused... ;-)

> Also if this is something that can be controlled before
> hand I prefer to test that the statement won't raise an error before issuing
> it, rather than letting the error happens and handle it afterward...

But this is definitely the best solution...
Author
18 Oct 2006 10:36 AM
Anand[MVP]
If you are using VB 2005, then there is a Continue statement, that will skip
to the next iteration of the For loop, without using Goto..

--
Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com


Show quoteHide quote
"Lucia" wrote:

> Hi, everyone,
>
> I have a for statement in my programm. I want to know if there is any
> way to goto next i when some error occurs. I tried with the following
> code. But it doesn't work...
>
> for i=0 to 100
>
> On Error Goto NEXTFOR
>
> .....
>
> NEXTFOR:
> next
>
> thanks a lot
>
> Lucia
>
>
Author
18 Oct 2006 12:01 PM
M. Posseth
for i=0 to 100

try
'code that might cause an error
catch ex as exception
'this will skipp the curent and move to the next
continue for 
end try

next

regards

Michel Posseth [MCP]



Show quoteHide quote
"Lucia" wrote:

> Hi, everyone,
>
> I have a for statement in my programm. I want to know if there is any
> way to goto next i when some error occurs. I tried with the following
> code. But it doesn't work...
>
> for i=0 to 100
>
> On Error Goto NEXTFOR
>
> .....
>
> NEXTFOR:
> next
>
> thanks a lot
>
> Lucia
>
>
Author
18 Oct 2006 12:07 PM
M. Posseth
ofcourse it would be much better if you could do something like this

PSEUDO CODE :

for i=0 to 100


---- check if value is within the expected range
if not expectedrangecode then 
continue for 
end if
--- do the rest of youyr stuff 
next

as this would give you a performance benefit   ( try catch statements have a
lot of overhead )   so if you can validate the values yourself without try
catch then implement this validation

regards

Michel 




Show quoteHide quote
"M. Posseth" wrote:

>
>  for i=0 to 100
>
> try
> 'code that might cause an error
> catch ex as exception
> 'this will skipp the curent and move to the next
> continue for 
> end try
>
>  next
>
> regards
>
> Michel Posseth [MCP]
>
>
>
> "Lucia" wrote:
>
> > Hi, everyone,
> >
> > I have a for statement in my programm. I want to know if there is any
> > way to goto next i when some error occurs. I tried with the following
> > code. But it doesn't work...
> >
> > for i=0 to 100
> >
> > On Error Goto NEXTFOR
> >
> > .....
> >
> > NEXTFOR:
> > next
> >
> > thanks a lot
> >
> > Lucia
> >
> >
Author
18 Oct 2006 1:38 PM
Lucia
Hallo, everybody,

thanks very much for your advice...

cheers

Lucia