PC Review


Reply
Thread Tools Rate Thread

On Error Goto Next Loop

 
 
Lucia
Guest
Posts: n/a
 
      18th Oct 2006
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

 
Reply With Quote
 
 
 
 
Patrice
Guest
Posts: n/a
 
      18th Oct 2006
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" <(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Norman Chong
Guest
Posts: n/a
 
      18th Oct 2006
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...

 
Reply With Quote
 
=?Utf-8?B?QW5hbmRbTVZQXQ==?=
Guest
Posts: n/a
 
      18th Oct 2006
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


"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
>
>

 
Reply With Quote
 
=?Utf-8?B?TS4gUG9zc2V0aA==?=
Guest
Posts: n/a
 
      18th Oct 2006

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
>
>

 
Reply With Quote
 
=?Utf-8?B?TS4gUG9zc2V0aA==?=
Guest
Posts: n/a
 
      18th Oct 2006
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




"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
> >
> >

 
Reply With Quote
 
Lucia
Guest
Posts: n/a
 
      18th Oct 2006
Hallo, everybody,

thanks very much for your advice...

cheers

Lucia

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Jumping out of loop with GoTo function Andy Microsoft Excel Programming 2 28th Sep 2006 02:19 AM
On Error GoTo Label in a loop only working once. Ken Johnson Microsoft Excel Charting 4 5th Jul 2006 10:39 PM
On Error Goto doesn't goto =?Utf-8?B?UGF1bA==?= Microsoft Excel Programming 0 15th Oct 2004 04:05 PM
How Do You Make a Loop Iterate Early Without Using GoTo? eBob.com Microsoft VB .NET 6 11th Oct 2004 10:06 AM
GoTo Loop? JayL Microsoft Excel Programming 3 18th May 2004 03:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:51 PM.